This is an automated email from the ASF dual-hosted git repository.
myui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hivemall.git
The following commit(s) were added to refs/heads/master by this push:
new ab1ce5d Renamed map_index UDF to map_get
ab1ce5d is described below
commit ab1ce5d4ec124f83ffb7d7b3ad48750fc854d0f9
Author: Makoto Yui <[email protected]>
AuthorDate: Thu Feb 7 15:12:39 2019 +0900
Renamed map_index UDF to map_get
---
.../tools/map/{MapIndexUDF.java => MapGetUDF.java} | 34 ++++++++++++----------
docs/gitbook/misc/generic_funcs.md | 2 +-
resources/ddl/define-all-as-permanent.hive | 4 +--
resources/ddl/define-all.deprecated.hive | 3 ++
resources/ddl/define-all.hive | 4 +--
resources/ddl/define-all.spark | 4 +--
6 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/core/src/main/java/hivemall/tools/map/MapIndexUDF.java
b/core/src/main/java/hivemall/tools/map/MapGetUDF.java
similarity index 79%
rename from core/src/main/java/hivemall/tools/map/MapIndexUDF.java
rename to core/src/main/java/hivemall/tools/map/MapGetUDF.java
index 73ffa36..3ea1138 100644
--- a/core/src/main/java/hivemall/tools/map/MapIndexUDF.java
+++ b/core/src/main/java/hivemall/tools/map/MapGetUDF.java
@@ -18,6 +18,8 @@
*/
package hivemall.tools.map;
+import hivemall.utils.lang.StringUtils;
+
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
@@ -32,20 +34,20 @@ import
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.C
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
//@formatter:off
-@Description(name = "map_index",
- value = "_FUNC_(a, n) - Returns the n-th element of the given array",
- extended = "WITH tmp as (\n" +
- " SELECT \"one\" as key\n" +
- " UNION ALL\n" +
- " SELECT \"two\" as key\n" +
- ")\n" +
- "SELECT map_index(map(\"one\",1,\"two\",2),key)\n" +
+@Description(name = "map_get",
+ value = "_FUNC_(MAP<K> a, K n) - Returns the value corresponding to
the key in the map",
+ extended = "WITH tmp as (\n" +
+ " SELECT \"one\" as key\n" +
+ " UNION ALL\n" +
+ " SELECT \"two\" as key\n" +
+ ")\n" +
+ "SELECT map_get(map(\"one\",1,\"two\",2),key)\n" +
"FROM tmp;\n\n" +
- "1\n" +
- "2")
+ "> 1\n" +
+ "> 2")
//@formatter:on
@UDFType(deterministic = true, stateful = false)
-public final class MapIndexUDF extends GenericUDF {
+public final class MapGetUDF extends GenericUDF {
private transient MapObjectInspector mapOI;
private transient Converter converter;
@@ -53,14 +55,15 @@ public final class MapIndexUDF extends GenericUDF {
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws
UDFArgumentException {
if (arguments.length != 2) {
- throw new UDFArgumentLengthException("The function INDEX accepts
exactly 2 arguments.");
+ throw new UDFArgumentLengthException("map_get accepts exactly 2
arguments.");
}
if (arguments[0] instanceof MapObjectInspector) {
this.mapOI = (MapObjectInspector) arguments[0];
} else {
- throw new UDFArgumentTypeException(0, "\"map\" is expected at
function INDEX, but \""
- + arguments[0].getTypeName() + "\" is found");
+ throw new UDFArgumentTypeException(0,
+ "\"map\" is expected for the first argument, but \"" +
arguments[0].getTypeName()
+ + "\" is found");
}
// index has to be a primitive
@@ -97,8 +100,7 @@ public final class MapIndexUDF extends GenericUDF {
@Override
public String getDisplayString(String[] children) {
- assert (children.length == 2);
- return children[0] + "[" + children[1] + "]";
+ return "map_get(" + StringUtils.join(children, ',') + ')';
}
}
diff --git a/docs/gitbook/misc/generic_funcs.md
b/docs/gitbook/misc/generic_funcs.md
index e99594b..b282731 100644
--- a/docs/gitbook/misc/generic_funcs.md
+++ b/docs/gitbook/misc/generic_funcs.md
@@ -434,7 +434,7 @@ This page describes a list of useful Hivemall generic
functions. See also a [lis
{2:"two",3:"three"}
```
-- `map_index(a, n)` - Returns the n-th element of the given array
+- `map_get(Map<K> a, K n)` - Returns the value corresponding to the key in the
map
```sql
WITH tmp as (
SELECT "one" as key
diff --git a/resources/ddl/define-all-as-permanent.hive
b/resources/ddl/define-all-as-permanent.hive
index 5e2be02..0c836f2 100644
--- a/resources/ddl/define-all-as-permanent.hive
+++ b/resources/ddl/define-all-as-permanent.hive
@@ -509,8 +509,8 @@ CREATE FUNCTION map_include_keys as
'hivemall.tools.map.MapIncludeKeysUDF' USING
DROP FUNCTION IF EXISTS map_exclude_keys;
CREATE FUNCTION map_exclude_keys as 'hivemall.tools.map.MapExcludeKeysUDF'
USING JAR '${hivemall_jar}';
-DROP FUNCTION IF EXISTS map_index;
-CREATE FUNCTION map_index as 'hivemall.tools.map.MapIndexUDF' USING JAR
'${hivemall_jar}';
+DROP FUNCTION IF EXISTS map_get;
+CREATE FUNCTION map_get as 'hivemall.tools.map.MapGetUDF' USING JAR
'${hivemall_jar}';
DROP FUNCTION IF EXISTS map_key_values;
CREATE FUNCTION map_key_values as 'hivemall.tools.map.MapKeyValuesUDF' USING
JAR '${hivemall_jar}';
diff --git a/resources/ddl/define-all.deprecated.hive
b/resources/ddl/define-all.deprecated.hive
index ded195f..0c5566d 100644
--- a/resources/ddl/define-all.deprecated.hive
+++ b/resources/ddl/define-all.deprecated.hive
@@ -75,3 +75,6 @@ create temporary function addBias as
'hivemall.ftvec.AddBiasUDF';
drop temporary function if exists sha1;
create temporary function sha1 as 'hivemall.ftvec.hashing.Sha1UDF';
+
+drop temporary function if exists map_index;
+create temporary function map_index as 'hivemall.tools.map.MapGetUDF';
diff --git a/resources/ddl/define-all.hive b/resources/ddl/define-all.hive
index 6c6d929..e6f7c0b 100644
--- a/resources/ddl/define-all.hive
+++ b/resources/ddl/define-all.hive
@@ -501,8 +501,8 @@ create temporary function map_include_keys as
'hivemall.tools.map.MapIncludeKeys
drop temporary function if exists map_exclude_keys;
create temporary function map_exclude_keys as
'hivemall.tools.map.MapExcludeKeysUDF';
-drop temporary function if exists map_index;
-create temporary function map_index as 'hivemall.tools.map.MapIndexUDF';
+drop temporary function if exists map_get;
+create temporary function map_get as 'hivemall.tools.map.MapGetUDF';
drop temporary function if exists map_key_values;
create temporary function map_key_values as
'hivemall.tools.map.MapKeyValuesUDF';
diff --git a/resources/ddl/define-all.spark b/resources/ddl/define-all.spark
index 466e48b..e3ff216 100644
--- a/resources/ddl/define-all.spark
+++ b/resources/ddl/define-all.spark
@@ -500,8 +500,8 @@ sqlContext.sql("CREATE TEMPORARY FUNCTION map_include_keys
AS 'hivemall.tools.ma
sqlContext.sql("DROP TEMPORARY FUNCTION IF EXISTS map_exclude_keys")
sqlContext.sql("CREATE TEMPORARY FUNCTION map_exclude_keys AS
'hivemall.tools.map.MapExcludeKeysUDF'")
-sqlContext.sql("DROP TEMPORARY FUNCTION IF EXISTS map_index")
-sqlContext.sql("CREATE TEMPORARY FUNCTION map_index AS
'hivemall.tools.map.MapIndexUDF'")
+sqlContext.sql("DROP TEMPORARY FUNCTION IF EXISTS map_get")
+sqlContext.sql("CREATE TEMPORARY FUNCTION map_get AS
'hivemall.tools.map.MapGetUDF'")
sqlContext.sql("DROP TEMPORARY FUNCTION IF EXISTS map_key_values")
sqlContext.sql("CREATE TEMPORARY FUNCTION map_key_values AS
'hivemall.tools.map.MapKeyValuesUDF'")