You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2016/11/22 22:47:49 UTC

hive git commit: HIVE-15236 : timestamp and date comparison should happen in timestamp (Ashutosh Chauhan via Jason Dere)

Repository: hive
Updated Branches:
  refs/heads/master b366cf7c8 -> c3107ef88


HIVE-15236 : timestamp and date comparison should happen in timestamp (Ashutosh Chauhan via Jason Dere)

Signed-off-by: Ashutosh Chauhan <ha...@apache.org>


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

Branch: refs/heads/master
Commit: c3107ef8897f8cf22f1f8e64904e0b60f621528f
Parents: b366cf7
Author: Ashutosh Chauhan <ha...@apache.org>
Authored: Thu Nov 17 15:21:12 2016 -0800
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Tue Nov 22 14:46:56 2016 -0800

----------------------------------------------------------------------
 .../hadoop/hive/ql/exec/FunctionRegistry.java   |  9 +++++
 .../hive/ql/exec/TestFunctionRegistry.java      |  2 ++
 .../queries/clientpositive/cast_on_constant.q   |  1 +
 .../clientpositive/cast_on_constant.q.out       | 36 ++++++++++++++++++++
 4 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/c3107ef8/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 83d78bc..87330ed 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
@@ -769,12 +769,21 @@ public final class FunctionRegistry {
 
     PrimitiveGrouping pgA = PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pcA);
     PrimitiveGrouping pgB = PrimitiveObjectInspectorUtils.getPrimitiveGrouping(pcB);
+
+    if (pgA == pgB) {
+      // grouping is same, but category is not.
+      if (pgA == PrimitiveGrouping.DATE_GROUP) {
+        // we got timestamp & date and timestamp has higher precedence than date
+        return TypeInfoFactory.timestampTypeInfo;
+      }
+    }
     // handle string types properly
     if (pgA == PrimitiveGrouping.STRING_GROUP && pgB == PrimitiveGrouping.STRING_GROUP) {
       // Compare as strings. Char comparison semantics may be different if/when implemented.
       return getTypeInfoForPrimitiveCategory(
           (PrimitiveTypeInfo)a, (PrimitiveTypeInfo)b,PrimitiveCategory.STRING);
     }
+
     // timestamp/date is higher precedence than String_GROUP
     if (pgA == PrimitiveGrouping.STRING_GROUP && pgB == PrimitiveGrouping.DATE_GROUP) {
       return b;

http://git-wip-us.apache.org/repos/asf/hive/blob/c3107ef8/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
index 2192a89..3589938 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java
@@ -275,6 +275,8 @@ public class TestFunctionRegistry extends TestCase {
         TypeInfoFactory.doubleTypeInfo);
     comparison(TypeInfoFactory.timestampTypeInfo, TypeInfoFactory.intTypeInfo,
         TypeInfoFactory.doubleTypeInfo);
+   comparison(TypeInfoFactory.timestampTypeInfo, TypeInfoFactory.dateTypeInfo,
+        TypeInfoFactory.timestampTypeInfo);
 
     comparison(TypeInfoFactory.stringTypeInfo, varchar10, TypeInfoFactory.stringTypeInfo);
     comparison(varchar10, TypeInfoFactory.stringTypeInfo, TypeInfoFactory.stringTypeInfo);

http://git-wip-us.apache.org/repos/asf/hive/blob/c3107ef8/ql/src/test/queries/clientpositive/cast_on_constant.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/cast_on_constant.q b/ql/src/test/queries/clientpositive/cast_on_constant.q
index aabb9c6..bd9d57a 100644
--- a/ql/src/test/queries/clientpositive/cast_on_constant.q
+++ b/ql/src/test/queries/clientpositive/cast_on_constant.q
@@ -3,5 +3,6 @@ explain select * from t1 where ts_field = "2016-01-23 00:00:00";
 explain select * from t1 where date_field = "2016-01-23";
 explain select * from t1 where ts_field = timestamp '2016-01-23 00:00:00';
 explain select * from t1 where date_field = date '2016-01-23';
+explain select * from t1 where date_field = ts_field;
 
 drop table t1;

http://git-wip-us.apache.org/repos/asf/hive/blob/c3107ef8/ql/src/test/results/clientpositive/cast_on_constant.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/cast_on_constant.q.out b/ql/src/test/results/clientpositive/cast_on_constant.q.out
index f8d6a0d..7f920f4 100644
--- a/ql/src/test/results/clientpositive/cast_on_constant.q.out
+++ b/ql/src/test/results/clientpositive/cast_on_constant.q.out
@@ -150,6 +150,42 @@ STAGE PLANS:
       Processor Tree:
         ListSink
 
+PREHOOK: query: explain select * from t1 where date_field = ts_field
+PREHOOK: type: QUERY
+POSTHOOK: query: explain select * from t1 where date_field = ts_field
+POSTHOOK: type: QUERY
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 depends on stages: Stage-1
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Map Operator Tree:
+          TableScan
+            alias: t1
+            Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE
+            Filter Operator
+              predicate: (CAST( date_field AS TIMESTAMP) = ts_field) (type: boolean)
+              Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE
+              Select Operator
+                expressions: ts_field (type: timestamp), date_field (type: date)
+                outputColumnNames: _col0, _col1
+                Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE
+                File Output Operator
+                  compressed: false
+                  Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE
+                  table:
+                      input format: org.apache.hadoop.mapred.SequenceFileInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
+                      serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+      Processor Tree:
+        ListSink
+
 PREHOOK: query: drop table t1
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@t1