drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject [2/3] drill git commit: DRILL-3769: Allow to_date() to use castDate()'s implementations
Date Fri, 23 Oct 2015 06:28:56 GMT
DRILL-3769: Allow to_date() to use castDate()'s implementations


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

Branch: refs/heads/master
Commit: 17abf36adf54ef73e151c21497b0fdba9e7864fa
Parents: ef078da
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Mon Oct 12 22:52:05 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Thu Oct 22 23:14:27 2015 -0700

----------------------------------------------------------------------
 exec/java-exec/src/main/codegen/data/Casts.tdd  |  2 +-
 .../main/codegen/templates/CastDateDate.java    |  8 +++++++-
 .../drill/exec/fn/impl/TestCastFunctions.java   | 21 ++++++++++++++++----
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/17abf36a/exec/java-exec/src/main/codegen/data/Casts.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/Casts.tdd b/exec/java-exec/src/main/codegen/data/Casts.tdd
index 7d4914c..6b5420f 100644
--- a/exec/java-exec/src/main/codegen/data/Casts.tdd
+++ b/exec/java-exec/src/main/codegen/data/Casts.tdd
@@ -55,7 +55,7 @@
     {from: "VarBinary", to: "VarBinary", major: "SrcVarlenTargetVarlen"},
 
     {from: "Date", to: "TimeStamp", major: "Date"},
-    {from: "TimeStamp", to: "Date", major: "Date"},
+    {from: "TimeStamp", to: "Date", major: "Date", alias: "to_date"},
 
     {from: "VarChar", to: "Date", major: "VarCharDate", alias: "datetype"},
     {from: "VarChar", to: "TimeStamp", major: "VarCharDate", alias: "timestamptype"},

http://git-wip-us.apache.org/repos/asf/drill/blob/17abf36a/exec/java-exec/src/main/codegen/templates/CastDateDate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/CastDateDate.java b/exec/java-exec/src/main/codegen/templates/CastDateDate.java
index 1cd0b5a..c686917 100644
--- a/exec/java-exec/src/main/codegen/templates/CastDateDate.java
+++ b/exec/java-exec/src/main/codegen/templates/CastDateDate.java
@@ -42,7 +42,13 @@ import org.joda.time.DateMidnight;
 import org.apache.drill.exec.expr.fn.impl.DateUtility;
 
 @SuppressWarnings("unused")
-@FunctionTemplate(name = "cast${type.to?upper_case}", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls=NullHandling.NULL_IF_NULL, costCategory=FunctionCostCategory.COMPLEX)
+@FunctionTemplate(
+        <#if type.to == "Date">
+        names = {"cast${type.to?upper_case}", "${type.alias}"}
+        <#elseif type.to == "TimeStamp">
+        name = "cast${type.to?upper_case}"
+        </#if>
+        , scope = FunctionTemplate.FunctionScope.SIMPLE, nulls=NullHandling.NULL_IF_NULL,
costCategory=FunctionCostCategory.COMPLEX)
 public class Cast${type.from}To${type.to} implements DrillSimpleFunc {
 
   @Param ${type.from}Holder in;

http://git-wip-us.apache.org/repos/asf/drill/blob/17abf36a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
index 286c1d4..23fc54e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java
@@ -17,13 +17,12 @@
  */
 package org.apache.drill.exec.fn.impl;
 
-
 import org.apache.drill.BaseTestQuery;
+import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.common.util.FileUtils;
+import org.joda.time.DateTime;
 import org.junit.Test;
 
-import java.util.Date;
-
 public class TestCastFunctions extends BaseTestQuery {
 
   @Test
@@ -66,4 +65,18 @@ public class TestCastFunctions extends BaseTestQuery {
         .build()
         .run();
   }
-}
+
+  @Test // DRILL-3769
+  public void testToDateForTimeStamp() throws Exception {
+    final String query = "select to_date(to_timestamp(-1)) as col \n" +
+        "from (values(1))";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("col")
+        .baselineValues(new DateTime(1969, 12, 31, 0, 0))
+        .build()
+        .run();
+  }
+}
\ No newline at end of file


Mime
View raw message