hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject hive git commit: HIVE-12502: to_date UDF cannot accept NULLs of VOID type (Aaron Tokhy via Jason Dere)
Date Tue, 05 Jan 2016 01:15:09 GMT
Repository: hive
Updated Branches:
  refs/heads/branch-1 c4fb94d00 -> 05e609638


HIVE-12502: to_date UDF cannot accept NULLs of VOID type (Aaron Tokhy via Jason Dere)


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

Branch: refs/heads/branch-1
Commit: 05e6096381fcc09212df4308cf89cf9795c06571
Parents: c4fb94d
Author: Jason Dere <jdere@hortonworks.com>
Authored: Mon Jan 4 16:31:58 2016 -0800
Committer: Jason Dere <jdere@hortonworks.com>
Committed: Mon Jan 4 16:32:58 2016 -0800

----------------------------------------------------------------------
 .../hive/ql/udf/generic/GenericUDFDate.java     |  4 ++++
 .../hive/ql/udf/generic/TestGenericUDFDate.java | 23 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/05e60963/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDate.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDate.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDate.java
index 86a0714..10e648e 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDate.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDate.java
@@ -74,6 +74,8 @@ public class GenericUDFDate extends GenericUDF {
     inputType = argumentOI.getPrimitiveCategory();
     ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
     switch (inputType) {
+    case VOID:
+      break;
     case CHAR:
     case VARCHAR:
     case STRING:
@@ -103,6 +105,8 @@ public class GenericUDFDate extends GenericUDF {
     }
 
     switch (inputType) {
+    case VOID:
+      throw new UDFArgumentException("TO_DATE() received non-null object of VOID type");
     case STRING:
       Date date;
       String dateString = textConverter.convert(arguments[0].get()).toString();

http://git-wip-us.apache.org/repos/asf/hive/blob/05e60963/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDate.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDate.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDate.java
index 0c4928e..c9f566d 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDate.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDate.java
@@ -23,6 +23,7 @@ import java.sql.Timestamp;
 
 import junit.framework.TestCase;
 
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
 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;
@@ -89,4 +90,26 @@ public class TestGenericUDFDate extends TestCase {
     assertNull("to_date() with null DATE", output);
   }
 
+  public void testVoidToDate() throws HiveException {
+    GenericUDFDate udf = new GenericUDFDate();
+    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
+    ObjectInspector[] arguments = {valueOI};
+
+    udf.initialize(arguments);
+    DeferredObject[] args = { new DeferredJavaObject(null) };
+    Text output = (Text) udf.evaluate(args);
+
+    // Try with null VOID
+    assertNull("to_date() with null DATE ", output);
+
+    // Try with erroneously generated VOID
+    DeferredObject[] junkArgs = { new DeferredJavaObject(new Text("2015-11-22")) };
+    try {
+      udf.evaluate(junkArgs);
+      fail("to_date() test with VOID non-null failed");
+    } catch (UDFArgumentException udfae) {
+      assertEquals("TO_DATE() received non-null object of VOID type", udfae.getMessage());
+    }
+  }
+
 }


Mime
View raw message