hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject hive git commit: HIVE-14658 : UDF abs throws NPE when input arg type is string (Niklaus Xiao via Ashutosh Chauhan)
Date Wed, 31 Aug 2016 00:30:21 GMT
Repository: hive
Updated Branches:
  refs/heads/master 20824f27b -> ec4673bbc


HIVE-14658 : UDF abs throws NPE when input arg type is string (Niklaus Xiao via Ashutosh Chauhan)

Signed-off-by: Ashutosh Chauhan <hashutosh@apache.org>


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

Branch: refs/heads/master
Commit: ec4673bbc61b2555ef2d992266055a331443b4d6
Parents: 20824f2
Author: niklaus xiao <stone_xy@live.cn>
Authored: Tue Aug 30 17:29:37 2016 -0700
Committer: Ashutosh Chauhan <hashutosh@apache.org>
Committed: Tue Aug 30 17:29:37 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java   | 3 +++
 .../apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java   | 6 ++++++
 2 files changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/ec4673bb/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java
index 1fdd41c..a8e2786 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java
@@ -130,6 +130,9 @@ public class GenericUDFAbs extends GenericUDF {
     case STRING:
     case DOUBLE:
       valObject = inputConverter.convert(valObject);
+      if (valObject == null) {
+        return null;
+      }
       resultDouble.set(Math.abs(((DoubleWritable) valObject).get()));
       return resultDouble;
     case DECIMAL:

http://git-wip-us.apache.org/repos/asf/hive/blob/ec4673bb/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java
index 8c531ea..6dbb33f 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAbs.java
@@ -133,6 +133,12 @@ public class TestGenericUDFAbs extends TestCase {
     output = (DoubleWritable) udf.evaluate(args);
 
     assertEquals("abs() test for String failed ", "123.45", output.toString());
+
+    valueObj = new DeferredJavaObject(new Text("foo"));
+    args[0] = valueObj;
+    output = (DoubleWritable) udf.evaluate(args);
+
+    assertEquals("abs() test for String failed ", null, output);
   }
 
   public void testHiveDecimal() throws HiveException {


Mime
View raw message