hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject svn commit: r1670405 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java test/queries/clientpositive/udf_format_number.q test/results/clientpositive/udf_format_number.q.out
Date Tue, 31 Mar 2015 17:37:24 GMT
Author: jdere
Date: Tue Mar 31 17:37:24 2015
New Revision: 1670405

URL: http://svn.apache.org/r1670405
Log:
HIVE-10095: format_number udf throws NPE (Alex Pivovarov via Jason Dere)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java
    hive/trunk/ql/src/test/queries/clientpositive/udf_format_number.q
    hive/trunk/ql/src/test/results/clientpositive/udf_format_number.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java?rev=1670405&r1=1670404&r2=1670405&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFormatNumber.java
Tue Mar 31 17:37:24 2015
@@ -147,7 +147,13 @@ public class GenericUDFFormatNumber exte
 
   @Override
   public Object evaluate(DeferredObject[] arguments) throws HiveException {
-    int dValue = ((IntObjectInspector) argumentOIs[1]).get(arguments[1].get());
+    Object arg0;
+    Object arg1;
+    if ((arg0 = arguments[0].get()) == null || (arg1 = arguments[1].get()) == null) {
+      return null;
+    }
+
+    int dValue = ((IntObjectInspector) argumentOIs[1]).get(arg1);
 
     if (dValue < 0) {
       throw new HiveException("Argument 2 of function FORMAT_NUMBER must be >= 0, but
\""
@@ -181,26 +187,26 @@ public class GenericUDFFormatNumber exte
     switch (xObjectInspector.getPrimitiveCategory()) {
       case VOID:
       case DOUBLE:
-        xDoubleValue = ((DoubleObjectInspector) argumentOIs[0]).get(arguments[0].get());
+        xDoubleValue = ((DoubleObjectInspector) argumentOIs[0]).get(arg0);
         resultText.set(numberFormat.format(xDoubleValue));
         break;
       case FLOAT:
-        xFloatValue = ((FloatObjectInspector) argumentOIs[0]).get(arguments[0].get());
+        xFloatValue = ((FloatObjectInspector) argumentOIs[0]).get(arg0);
         resultText.set(numberFormat.format(xFloatValue));
         break;
       case DECIMAL:
         xDecimalValue = ((HiveDecimalObjectInspector) argumentOIs[0])
-            .getPrimitiveJavaObject(arguments[0].get());
+            .getPrimitiveJavaObject(arg0);
         resultText.set(numberFormat.format(xDecimalValue.bigDecimalValue()));
         break;
       case BYTE:
       case SHORT:
       case INT:
-        xIntValue = ((IntObjectInspector) argumentOIs[0]).get(arguments[0].get());
+        xIntValue = ((IntObjectInspector) argumentOIs[0]).get(arg0);
         resultText.set(numberFormat.format(xIntValue));
         break;
       case LONG:
-        xLongValue = ((LongObjectInspector) argumentOIs[0]).get(arguments[0].get());
+        xLongValue = ((LongObjectInspector) argumentOIs[0]).get(arg0);
         resultText.set(numberFormat.format(xLongValue));
         break;
       default:

Modified: hive/trunk/ql/src/test/queries/clientpositive/udf_format_number.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_format_number.q?rev=1670405&r1=1670404&r2=1670405&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_format_number.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_format_number.q Tue Mar 31 17:37:24
2015
@@ -71,3 +71,9 @@ SELECT format_number(12332.123456BD, 4),
     format_number(-12332.2BD, 0),
     format_number(CAST(12332.567 AS DECIMAL(8, 1)), 4)
 FROM src tablesample (1 rows);
+
+-- nulls
+SELECT
+  format_number(cast(null as int), 0),
+  format_number(12332.123456BD, cast(null as int)),
+  format_number(cast(null as int), cast(null as int));

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_format_number.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_format_number.q.out?rev=1670405&r1=1670404&r2=1670405&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_format_number.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_format_number.q.out Tue Mar 31 17:37:24
2015
@@ -211,3 +211,20 @@ POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
 12,332.1235	12,332.12	12,332.1000	-12,332	12,332.6000
+PREHOOK: query: -- nulls
+SELECT
+  format_number(cast(null as int), 0),
+  format_number(12332.123456BD, cast(null as int)),
+  format_number(cast(null as int), cast(null as int))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: -- nulls
+SELECT
+  format_number(cast(null as int), 0),
+  format_number(12332.123456BD, cast(null as int)),
+  format_number(cast(null as int), cast(null as int))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+NULL	NULL	NULL



Mime
View raw message