drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [19/27] git commit: DRILL-1186: Check for null values in Nullable Date/Time/TimeStamp SqlAccessors
Date Sun, 27 Jul 2014 18:47:05 GMT
DRILL-1186: Check for null values in Nullable Date/Time/TimeStamp SqlAccessors


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

Branch: refs/heads/master
Commit: 9b2eae24a1b667e7e23c1a490803565722083882
Parents: 3a73b3e
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Thu Jul 24 11:41:01 2014 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Fri Jul 25 14:34:30 2014 -0700

----------------------------------------------------------------------
 .../src/main/codegen/templates/SqlAccessors.java     | 15 +++++++++++++++
 .../apache/drill/jdbc/test/TestFunctionsQuery.java   | 10 ++++++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/9b2eae24/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
index a5b251e..a9eb3fe 100644
--- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
+++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java
@@ -129,6 +129,11 @@ public class ${name}Accessor extends AbstractSqlAccessor{
 
   @Override
   public Date getDate(int index) {
+    <#if mode == "Nullable">
+    if (ac.isNull(index)) {
+      return null;
+    }
+    </#if>
     org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
     date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
     return new Date(date.getMillis());
@@ -140,6 +145,11 @@ public class ${name}Accessor extends AbstractSqlAccessor{
 
   @Override
   public Timestamp getTimestamp(int index) {
+    <#if mode == "Nullable">
+    if (ac.isNull(index)) {
+      return null;
+    }
+    </#if>
     org.joda.time.DateTime date = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
     date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
     return new Timestamp(date.getMillis());
@@ -151,6 +161,11 @@ public class ${name}Accessor extends AbstractSqlAccessor{
 
   @Override
   public Time getTime(int index) {
+    <#if mode == "Nullable">
+    if (ac.isNull(index)) {
+      return null;
+    }
+    </#if>
     org.joda.time.DateTime time = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
     time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
     return new Time(time.getMillis());

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/9b2eae24/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
index 4651b1e..5aee392 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java
@@ -466,6 +466,16 @@ public class TestFunctionsQuery {
   }
 
   @Test
+  public void testNullConstantsTimeTimeStampAndDate() throws Exception {
+    JdbcAssert.withNoDefaultSchema()
+        .sql("SELECT CAST(NULL AS TIME) AS t, " +
+            "CAST(NULL AS TIMESTAMP) AS ts, " +
+            "CAST(NULL AS DATE) AS d " +
+            "FROM cp.`region.json` LIMIT 1")
+        .returns("t=null; ts=null; d=null");
+  }
+
+  @Test
   public void testIntMinToDecimal() throws Exception {
     String query = "select cast((employee_id - employee_id + -2147483648) as decimal(28,
2)) as DEC_28," +
                    "cast((employee_id - employee_id + -2147483648) as decimal(18, 2)) as
DEC_18 from " +


Mime
View raw message