HIVE-16050: Regression: Union of null with non-null (Gopal V, reviewed by 
Sergey Shelukhin)

(cherry-picked: a6366fc07931f374af77d0ab208404027bf165a3)

Change-Id: I65d05a2385f712bec0f41269c2498136b60fba0d


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

Branch: refs/heads/branch-2.2
Commit: d8f54cdad4b97543e89b250817f4280a55dc288d
Parents: 859574f
Author: Gopal V <gop...@apache.org>
Authored: Wed Mar 1 17:57:54 2017 +0530
Committer: Owen O'Malley <omal...@apache.org>
Committed: Tue Mar 28 14:02:47 2017 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hive/ql/exec/FunctionRegistry.java  |  9 +++++++++
 ql/src/test/queries/clientpositive/union_null.q           |  3 +++
 ql/src/test/results/clientpositive/spark/union_null.q.out | 10 ++++++++++
 ql/src/test/results/clientpositive/union_null.q.out       | 10 ++++++++++
 4 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/d8f54cda/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
index d8198c6..84c218f 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
@@ -725,6 +725,15 @@ public final class FunctionRegistry {
 
     PrimitiveGrouping pgA = 
PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pcA);
     PrimitiveGrouping pgB = 
PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pcB);
+
+    // untyped nulls
+    if (pgA == PrimitiveGrouping.VOID_GROUP) {
+      return b;
+    }
+    if (pgB == PrimitiveGrouping.VOID_GROUP) {
+      return a;
+    }
+
     if (pgA != pgB) {
       return null;
     }

http://git-wip-us.apache.org/repos/asf/hive/blob/d8f54cda/ql/src/test/queries/clientpositive/union_null.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/union_null.q 
b/ql/src/test/queries/clientpositive/union_null.q
index 45448b4..aacf310 100644
--- a/ql/src/test/queries/clientpositive/union_null.q
+++ b/ql/src/test/queries/clientpositive/union_null.q
@@ -8,3 +8,6 @@ select x from (select * from (select value as x from src order 
by x limit 5)a un
 set hive.cbo.returnpath.hiveop=false;
 -- HIVE-4837
 select * from (select * from (select cast(null as string) as N from src1 group 
by key)a UNION ALL select * from (select cast(null as string) as N from src1 
group by key)b ) a;
+
+-- HIVE-16050
+select null as c1 UNION ALL select 1 as c1;

http://git-wip-us.apache.org/repos/asf/hive/blob/d8f54cda/ql/src/test/results/clientpositive/spark/union_null.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/spark/union_null.q.out 
b/ql/src/test/results/clientpositive/spark/union_null.q.out
index 49482b2..76f5ac8 100644
--- a/ql/src/test/results/clientpositive/spark/union_null.q.out
+++ b/ql/src/test/results/clientpositive/spark/union_null.q.out
@@ -95,3 +95,13 @@ NULL
 NULL
 NULL
 NULL
+PREHOOK: query: select null as c1 UNION ALL select 1 as c1
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select null as c1 UNION ALL select 1 as c1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+NULL
+1

http://git-wip-us.apache.org/repos/asf/hive/blob/d8f54cda/ql/src/test/results/clientpositive/union_null.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/union_null.q.out 
b/ql/src/test/results/clientpositive/union_null.q.out
index e196ff3..00bd9d9 100644
--- a/ql/src/test/results/clientpositive/union_null.q.out
+++ b/ql/src/test/results/clientpositive/union_null.q.out
@@ -74,3 +74,13 @@ NULL
 NULL
 NULL
 NULL
+PREHOOK: query: select null as c1 UNION ALL select 1 as c1
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select null as c1 UNION ALL select 1 as c1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+NULL
+1

Reply via email to