drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [06/14] drill git commit: DRILL-5048: Fix type mismatch error in case statement with null timestamp
Date Tue, 13 Dec 2016 00:40:03 GMT
DRILL-5048: Fix type mismatch error in case statement with null timestamp

closes #657


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

Branch: refs/heads/master
Commit: 85a9651844c3e5f33db14c57b8f43f01100a729e
Parents: 3cd2f44
Author: Serhii-Harnyk <serhii.harnyk@gmail.com>
Authored: Thu Nov 17 14:23:58 2016 +0000
Committer: Sudheesh Katkam <sudheesh@apache.org>
Committed: Mon Dec 12 15:40:02 2016 -0800

----------------------------------------------------------------------
 .../exec/planner/logical/DrillConstExecutor.java     |  3 ++-
 .../exec/planner/logical/TestCaseNullableTypes.java  | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/85a96518/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
index 4a0f8fa..829db2a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java
@@ -287,7 +287,8 @@ public class DrillConstExecutor implements RelOptPlanner.Executor {
               Calendar value = (materializedExpr.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL)
?
                 new DateTime(((NullableTimeStampHolder) output).value, DateTimeZone.UTC).toCalendar(null)
:
                 new DateTime(((TimeStampHolder) output).value, DateTimeZone.UTC).toCalendar(null);
-              return rexBuilder.makeTimestampLiteral(value, 0);
+              return rexBuilder.makeLiteral(value,
+                TypeInferenceUtils.createCalciteTypeWithNullability(typeFactory, SqlTypeName.TIMESTAMP,
newCall.getType().isNullable()), false);
             }
             case INTERVALYEAR: {
               BigDecimal value = (materializedExpr.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL)
?

http://git-wip-us.apache.org/repos/asf/drill/blob/85a96518/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestCaseNullableTypes.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestCaseNullableTypes.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestCaseNullableTypes.java
index 8e5245f..4db59eb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestCaseNullableTypes.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/TestCaseNullableTypes.java
@@ -17,6 +17,8 @@
 package org.apache.drill.exec.planner.logical;
 
 import org.apache.drill.BaseTestQuery;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
 import org.junit.Test;
 
 /**
@@ -124,4 +126,17 @@ public class TestCaseNullableTypes extends BaseTestQuery {
       .baselineValues(1, 0.1f)
       .go();
   }
+
+  @Test //DRILL-5048
+  public void testCaseNullableTimestamp() throws Exception {
+    DateTime date = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
+      .parseDateTime("2016-11-17 14:43:23");
+
+    testBuilder()
+      .sqlQuery("SELECT (CASE WHEN (false) THEN null ELSE CAST('2016-11-17 14:43:23' AS TIMESTAMP)
END) res FROM (values(1)) foo")
+      .unOrdered()
+      .baselineColumns("res")
+      .baselineValues(date)
+      .go();
+  }
 }


Mime
View raw message