drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [09/17] git commit: DRILL-1140: Add cast function from Timestamp to Time
Date Mon, 21 Jul 2014 02:46:31 GMT
DRILL-1140: Add cast function from Timestamp to Time


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

Branch: refs/heads/master
Commit: 2beeda036dda40b17d8f9fc440ff0d3e2309d314
Parents: c924273
Author: Mehant Baid <mehantr@gmail.com>
Authored: Tue Jul 15 01:33:36 2014 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Sun Jul 20 16:31:18 2014 -0700

----------------------------------------------------------------------
 .../drill/common/expression/ValueExpressions.java    |  7 ++++++-
 .../drill/exec/expr/fn/impl/DateTypeFunctions.java   | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2beeda03/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index db501aa..a1f69c2 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -60,7 +60,12 @@ public class ValueExpressions {
   }
 
   public static LogicalExpression getTime(GregorianCalendar time) {
-      return new TimeExpression((int) time.getTimeInMillis());
+      int millis = time.get(GregorianCalendar.HOUR_OF_DAY) * 60 * 60 * 1000 +
+                   time.get(GregorianCalendar.MINUTE) * 60 * 1000 +
+                   time.get(GregorianCalendar.SECOND) * 1000 +
+                   time.get(GregorianCalendar.MILLISECOND);
+
+      return new TimeExpression(millis);
   }
 
   public static LogicalExpression getTimeStamp(GregorianCalendar date) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2beeda03/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
index 2349ddf..725566f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/DateTypeFunctions.java
@@ -456,4 +456,19 @@ public class DateTypeFunctions {
             out.milliSeconds = (int) (diff % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
         }
     }
+
+    @FunctionTemplate(name = "castTIME", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= NullHandling.NULL_IF_NULL)
+    public static class CastTimeStampToTime implements DrillSimpleFunc {
+        @Param TimeStampHolder in;
+        @Output TimeHolder out;
+
+        @Override
+        public void setup(RecordBatch incoming) {
+        }
+
+        @Override
+        public void eval() {
+            out.value = (int) (in.value % org.apache.drill.exec.expr.fn.impl.DateUtility.daysToStandardMillis);
+        }
+    }
 }


Mime
View raw message