You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2016/08/25 18:16:30 UTC

hive git commit: HIVE-14617: NPE in UDF MapValues() if input is null (reviewed by Chao)

Repository: hive
Updated Branches:
  refs/heads/master 9343fee5d -> 2f686d4c0


HIVE-14617: NPE in UDF MapValues() if input is null (reviewed by Chao)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/2f686d4c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/2f686d4c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/2f686d4c

Branch: refs/heads/master
Commit: 2f686d4c0c20540079660de202c619e42ed5cd4f
Parents: 9343fee
Author: Xuefu Zhang <xu...@uber.com>
Authored: Thu Aug 25 11:05:25 2016 -0700
Committer: Xuefu Zhang <xu...@uber.com>
Committed: Thu Aug 25 11:05:25 2016 -0700

----------------------------------------------------------------------
 .../ql/udf/generic/GenericUDFMapValues.java     |  6 ++-
 .../ql/udf/generic/TestGenericUDFMapValues.java | 56 ++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/2f686d4c/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFMapValues.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFMapValues.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFMapValues.java
index 096ceac..3bd5864 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFMapValues.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFMapValues.java
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.ql.udf.generic;
 
 import java.util.ArrayList;
+import java.util.Map;
 
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
@@ -61,7 +62,10 @@ public class GenericUDFMapValues extends GenericUDF {
   public Object evaluate(DeferredObject[] arguments) throws HiveException {
     retArray.clear();
     Object mapObj = arguments[0].get();
-    retArray.addAll(mapOI.getMap(mapObj).values());
+    Map<?, ?> map = mapOI.getMap(mapObj);
+    if (map != null) {
+      retArray.addAll(map.values());
+    }
     return retArray;
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/2f686d4c/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFMapValues.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFMapValues.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFMapValues.java
new file mode 100644
index 0000000..44676ed
--- /dev/null
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFMapValues.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestGenericUDFMapValues {
+
+  @Test
+  public void testNullMap() throws HiveException, IOException {
+    ObjectInspector[] inputOIs = {
+        ObjectInspectorFactory.getStandardMapObjectInspector(
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+            PrimitiveObjectInspectorFactory.writableStringObjectInspector),
+    };
+
+    Map<String, String> input = null;
+    DeferredObject[] args = {
+        new DeferredJavaObject(input)
+    };
+
+  GenericUDFMapValues udf = new GenericUDFMapValues();
+    StandardListObjectInspector oi = (StandardListObjectInspector) udf.initialize(inputOIs);
+    Object res = udf.evaluate(args);
+    Assert.assertTrue(oi.getList(res).isEmpty());
+    udf.close();
+  }
+
+}