You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jd...@apache.org on 2014/10/15 03:53:48 UTC

svn commit: r1631930 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/exec/ test/org/apache/hadoop/hive/ql/exec/ test/queries/clientpositive/ test/results/clientpositive/

Author: jdere
Date: Wed Oct 15 01:53:48 2014
New Revision: 1631930

URL: http://svn.apache.org/r1631930
Log:
HIVE-8391: Comparion between TIMESTAMP and Integer types goes to STRING as "common comparison denominator" instead of a numeric type (Jason Dere, reviewed by Sergey Shelukhin)

Added:
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison2.q
    hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison2.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.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=1631930&r1=1631929&r2=1631930&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 Wed Oct 15 01:53:48 2014
@@ -982,6 +982,12 @@ public final class FunctionRegistry {
           (PrimitiveTypeInfo)a, (PrimitiveTypeInfo)b,PrimitiveCategory.STRING);
     }
 
+    // Another special case, because timestamp is not implicitly convertible to numeric types.
+    if ((pgA == PrimitiveGrouping.NUMERIC_GROUP || pgB == PrimitiveGrouping.NUMERIC_GROUP)
+        && (pcA == PrimitiveCategory.TIMESTAMP || pcB == PrimitiveCategory.TIMESTAMP)) {
+      return TypeInfoFactory.doubleTypeInfo;
+    }
+
     for (PrimitiveCategory t : numericTypeList) {
       if (FunctionRegistry.implicitConvertible(pcA, t)
           && FunctionRegistry.implicitConvertible(pcB, t)) {

Modified: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java?rev=1631930&r1=1631929&r2=1631930&view=diff
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java (original)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java Wed Oct 15 01:53:48 2014
@@ -256,6 +256,11 @@ public class TestFunctionRegistry extend
     comparison(TypeInfoFactory.stringTypeInfo, TypeInfoFactory.dateTypeInfo,
         TypeInfoFactory.stringTypeInfo);
 
+    comparison(TypeInfoFactory.intTypeInfo, TypeInfoFactory.timestampTypeInfo,
+        TypeInfoFactory.doubleTypeInfo);
+    comparison(TypeInfoFactory.timestampTypeInfo, TypeInfoFactory.intTypeInfo,
+        TypeInfoFactory.doubleTypeInfo);
+
     comparison(TypeInfoFactory.stringTypeInfo, varchar10, TypeInfoFactory.stringTypeInfo);
     comparison(varchar10, TypeInfoFactory.stringTypeInfo, TypeInfoFactory.stringTypeInfo);
     comparison(varchar5, varchar10, varchar10);

Added: hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison2.q?rev=1631930&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison2.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/timestamp_comparison2.q Wed Oct 15 01:53:48 2014
@@ -0,0 +1,23 @@
+-- Test timestamp-to-numeric comparison
+select count(*) 
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= 0) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > -29071) AND (3569 >= cdouble)))))
+;
+
+-- Should have same result as previous query
+select count(*)
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= timestamp('1969-12-31 16:00:00')) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > timestamp('1969-12-31 07:55:29')) AND (3569 >= cdouble)))))
+;

Added: hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison2.q.out?rev=1631930&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/timestamp_comparison2.q.out Wed Oct 15 01:53:48 2014
@@ -0,0 +1,54 @@
+PREHOOK: query: -- Test timestamp-to-numeric comparison
+select count(*) 
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= 0) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > -29071) AND (3569 >= cdouble)))))
+PREHOOK: type: QUERY
+PREHOOK: Input: default@alltypesorc
+#### A masked pattern was here ####
+POSTHOOK: query: -- Test timestamp-to-numeric comparison
+select count(*) 
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= 0) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > -29071) AND (3569 >= cdouble)))))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@alltypesorc
+#### A masked pattern was here ####
+1826
+PREHOOK: query: -- Should have same result as previous query
+select count(*)
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= timestamp('1969-12-31 16:00:00')) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > timestamp('1969-12-31 07:55:29')) AND (3569 >= cdouble)))))
+PREHOOK: type: QUERY
+PREHOOK: Input: default@alltypesorc
+#### A masked pattern was here ####
+POSTHOOK: query: -- Should have same result as previous query
+select count(*)
+FROM   alltypesorc
+WHERE  
+((ctinyint != 0)
+    AND 
+        (((ctimestamp1 <= timestamp('1969-12-31 16:00:00')) 
+            OR ((ctinyint = cint) OR (cstring2 LIKE 'ss')))
+         AND ((988888 < cdouble)
+             OR ((ctimestamp2 > timestamp('1969-12-31 07:55:29')) AND (3569 >= cdouble)))))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@alltypesorc
+#### A masked pattern was here ####
+1826