hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1310179 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java test/queries/clientpositive/union_null.q test/results/clientpositive/union_null.q.out
Date Fri, 06 Apr 2012 06:08:02 GMT
Author: namit
Date: Fri Apr  6 06:08:02 2012
New Revision: 1310179

URL: http://svn.apache.org/viewvc?rev=1310179&view=rev
Log:
HIVE-2901 Hive union with NULL constant and string in same column returns all null
(Navis via namit)


Added:
    hive/trunk/ql/src/test/queries/clientpositive/union_null.q
    hive/trunk/ql/src/test/results/clientpositive/union_null.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1310179&r1=1310178&r2=1310179&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Fri Apr  6
06:08:02 2012
@@ -631,6 +631,28 @@ public final class FunctionRegistry {
   }
 
   /**
+   * Find a common class for union-all operator
+   */
+  public static TypeInfo getCommonClassForUnionAll(TypeInfo a, TypeInfo b) {
+    if (a.equals(b)) {
+      return a;
+    }
+    if (FunctionRegistry.implicitConvertable(a, b)) {
+      return b;
+    }
+    if (FunctionRegistry.implicitConvertable(b, a)) {
+      return a;
+    }
+    for (TypeInfo t : numericTypeList) {
+      if (FunctionRegistry.implicitConvertable(a, t)
+          && FunctionRegistry.implicitConvertable(b, t)) {
+        return t;
+      }
+    }
+    return null;
+  }
+
+  /**
    * Find a common class that objects of both TypeInfo a and TypeInfo b can
    * convert to. This is used for comparing objects of type a and type b.
    *
@@ -644,7 +666,6 @@ public final class FunctionRegistry {
     if (a.equals(b)) {
       return a;
     }
-
     for (TypeInfo t : numericTypeList) {
       if (FunctionRegistry.implicitConvertable(a, t)
           && FunctionRegistry.implicitConvertable(b, t)) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1310179&r1=1310178&r2=1310179&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Fri Apr 
6 06:08:02 2012
@@ -6264,7 +6264,7 @@ public class SemanticAnalyzer extends Ba
             + ". Column positions should match for a UNION"));
       }
       //try widening coversion, otherwise fail union
-      TypeInfo commonTypeInfo = FunctionRegistry.getCommonClassForComparison(lInfo.getType(),
+      TypeInfo commonTypeInfo = FunctionRegistry.getCommonClassForUnionAll(lInfo.getType(),
           rInfo.getType());
       if (commonTypeInfo == null) {
         throw new SemanticException(generateErrorMessage(tabref,
@@ -6281,7 +6281,7 @@ public class SemanticAnalyzer extends Ba
       String field = lEntry.getKey();
       ColumnInfo lInfo = lEntry.getValue();
       ColumnInfo rInfo = rightmap.get(field);
-      lInfo.setType(FunctionRegistry.getCommonClassForComparison(lInfo.getType(),
+      lInfo.setType(FunctionRegistry.getCommonClassForUnionAll(lInfo.getType(),
             rInfo.getType()));
       unionoutRR.put(unionalias, field, lInfo);
     }

Added: hive/trunk/ql/src/test/queries/clientpositive/union_null.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/union_null.q?rev=1310179&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/union_null.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/union_null.q Fri Apr  6 06:08:02 2012
@@ -0,0 +1,2 @@
+-- HIVE-2901
+select x from (select value as x from src union all select NULL as x from src)a limit 10;

Added: hive/trunk/ql/src/test/results/clientpositive/union_null.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/union_null.q.out?rev=1310179&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/union_null.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/union_null.q.out Fri Apr  6 06:08:02 2012
@@ -0,0 +1,20 @@
+PREHOOK: query: -- HIVE-2901
+select x from (select value as x from src union all select NULL as x from src)a limit 10
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: -- HIVE-2901
+select x from (select value as x from src union all select NULL as x from src)a limit 10
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+val_238
+NULL
+val_86
+NULL
+val_311
+NULL
+val_27
+NULL
+val_165
+NULL



Mime
View raw message