HIVE-16562: Issues with nullif / fetch task (Zoltan Haindrich, reviewed by 
Ashutosh Chauhan)


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

Branch: refs/heads/master
Commit: 0f8840a31a73f7b3278735ea4fb9cd4b0f3ae8d3
Parents: ec8c390
Author: Zoltan Haindrich <k...@rxd.hu>
Authored: Mon May 8 07:21:40 2017 +0200
Committer: Zoltan Haindrich <k...@rxd.hu>
Committed: Mon May 8 07:44:07 2017 +0200

----------------------------------------------------------------------
 .../hive/ql/udf/generic/GenericUDFNullif.java   | 10 ++++--
 .../ql/udf/generic/TestGenericUDFNullif.java    | 20 +++++++++++
 ql/src/test/queries/clientpositive/udf_nullif.q | 11 ++++++
 .../results/clientpositive/udf_nullif.q.out     | 37 ++++++++++++++++++++
 4 files changed, 75 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/0f8840a3/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java
index 452c84e..5020ef8 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNullif.java
@@ -86,16 +86,20 @@ public class GenericUDFNullif extends GenericUDF {
   public Object evaluate(DeferredObject[] arguments) throws HiveException {
     Object arg0 = arguments[0].get();
     Object arg1 = arguments[1].get();
+    Object value0 = null;
+    if (arg0 != null) {
+      value0 = returnOIResolver.convertIfNecessary(arg0, argumentOIs[0], 
false);
+    }
     if (arg0 == null || arg1 == null) {
-      return arg0;
+      return value0;
     }
     PrimitiveObjectInspector compareOI = (PrimitiveObjectInspector) 
returnOIResolver.get();
     if (PrimitiveObjectInspectorUtils.comparePrimitiveObjects(
-        arg0, compareOI,
+        value0, compareOI,
         returnOIResolver.convertIfNecessary(arg1, argumentOIs[1], false), 
compareOI)) {
       return null;
     }
-    return arg0;
+    return value0;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hive/blob/0f8840a3/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNullif.java
----------------------------------------------------------------------
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNullif.java 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNullif.java
index a66e63e..3e6efd4 100644
--- 
a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNullif.java
+++ 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNullif.java
@@ -24,6 +24,8 @@ 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.io.ByteWritable;
 import org.apache.hadoop.hive.serde2.io.DateWritable;
+import org.apache.hadoop.hive.serde2.lazy.LazyInteger;
+import 
org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyPrimitiveObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
 import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
@@ -129,4 +131,22 @@ public class TestGenericUDFNullif {
     Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo());
     Assert.assertEquals(null, udf.evaluate(args));
   }
+
+  @Test
+  public void testLazy() throws HiveException {
+    GenericUDFNullif udf = new GenericUDFNullif();
+
+    ObjectInspector[] inputOIs = { 
LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR,
+        LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR };
+    LazyInteger a1 = new 
LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR);
+    LazyInteger a2 = new 
LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR);
+    a1.getWritableObject().set(1);
+    a2.getWritableObject().set(1);
+
+    DeferredObject[] args = { new DeferredJavaObject(a1), new 
DeferredJavaObject(a2) };
+
+    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) 
udf.initialize(inputOIs);
+    Assert.assertEquals(TypeInfoFactory.intTypeInfo, oi.getTypeInfo());
+    Assert.assertEquals(null, udf.evaluate(args));
+  }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/0f8840a3/ql/src/test/queries/clientpositive/udf_nullif.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/udf_nullif.q 
b/ql/src/test/queries/clientpositive/udf_nullif.q
index 8632837..00dfa23 100644
--- a/ql/src/test/queries/clientpositive/udf_nullif.q
+++ b/ql/src/test/queries/clientpositive/udf_nullif.q
@@ -16,3 +16,14 @@ select       nullif(date('2011-11-11'),date('2011-11-22'));
 select nullif(1,null);
 
 select nullif(1.0,1);
+
+
+set hive.fetch.task.conversion=more;
+
+drop table if exists t0;
+create table t0(a int,b int,c float,d double precision);
+insert into t0 values(1,2,3.1,4.1);
+select nullif(a,b),
+       nullif(b,c),
+       nullif(c,d),
+       nullif(d,a) from t0;

http://git-wip-us.apache.org/repos/asf/hive/blob/0f8840a3/ql/src/test/results/clientpositive/udf_nullif.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/udf_nullif.q.out 
b/ql/src/test/results/clientpositive/udf_nullif.q.out
index 12cfbec..65827bc 100644
--- a/ql/src/test/results/clientpositive/udf_nullif.q.out
+++ b/ql/src/test/results/clientpositive/udf_nullif.q.out
@@ -168,3 +168,40 @@ POSTHOOK: type: QUERY
 POSTHOOK: Input: _dummy_database@_dummy_table
 #### A masked pattern was here ####
 NULL
+PREHOOK: query: drop table if exists t0
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists t0
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: create table t0(a int,b int,c float,d double precision)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@t0
+POSTHOOK: query: create table t0(a int,b int,c float,d double precision)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@t0
+PREHOOK: query: insert into t0 values(1,2,3.1,4.1)
+PREHOOK: type: QUERY
+PREHOOK: Output: default@t0
+POSTHOOK: query: insert into t0 values(1,2,3.1,4.1)
+POSTHOOK: type: QUERY
+POSTHOOK: Output: default@t0
+POSTHOOK: Lineage: t0.a EXPRESSION 
[(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col1, 
type:string, comment:), ]
+POSTHOOK: Lineage: t0.b EXPRESSION 
[(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col2, 
type:string, comment:), ]
+POSTHOOK: Lineage: t0.c EXPRESSION 
[(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col3, 
type:string, comment:), ]
+POSTHOOK: Lineage: t0.d EXPRESSION 
[(values__tmp__table__1)values__tmp__table__1.FieldSchema(name:tmp_values_col4, 
type:string, comment:), ]
+PREHOOK: query: select nullif(a,b),
+       nullif(b,c),
+       nullif(c,d),
+       nullif(d,a) from t0
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t0
+#### A masked pattern was here ####
+POSTHOOK: query: select        nullif(a,b),
+       nullif(b,c),
+       nullif(c,d),
+       nullif(d,a) from t0
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t0
+#### A masked pattern was here ####
+1      2       3.1     4.1

Reply via email to