You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/07/14 22:56:46 UTC

git commit: [OPTIQ-345] AssertionError in RexToLixTranslator comparing to date literal

Repository: incubator-optiq
Updated Branches:
  refs/heads/master 33e80e21f -> aacbeb524


[OPTIQ-345] AssertionError in RexToLixTranslator comparing to date literal


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

Branch: refs/heads/master
Commit: aacbeb5246eb4ee52a1ea89094a4564153be66f3
Parents: 33e80e2
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Jul 14 13:02:38 2014 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jul 14 13:02:38 2014 -0700

----------------------------------------------------------------------
 .../optiq/rules/java/RexToLixTranslator.java    | 39 +++++--------
 .../hydromatic/optiq/runtime/SqlFunctions.java  |  4 ++
 .../net/hydromatic/optiq/test/JdbcTest.java     |  5 ++
 core/src/test/resources/sql/misc.oq             | 58 ++++++++++++++++++++
 4 files changed, 81 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/aacbeb52/core/src/main/java/net/hydromatic/optiq/rules/java/RexToLixTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/rules/java/RexToLixTranslator.java b/core/src/main/java/net/hydromatic/optiq/rules/java/RexToLixTranslator.java
index 34cf83e..0cd192c 100644
--- a/core/src/main/java/net/hydromatic/optiq/rules/java/RexToLixTranslator.java
+++ b/core/src/main/java/net/hydromatic/optiq/rules/java/RexToLixTranslator.java
@@ -434,6 +434,7 @@ public class RexToLixTranslator {
       case NOT_POSSIBLE:
         throw AlwaysNull.INSTANCE;
       case NULL:
+      default:
         return RexImpTable.NULL_EXPR;
       }
     } else {
@@ -449,43 +450,31 @@ public class RexToLixTranslator {
     switch (literal.getType().getSqlTypeName()) {
     case DECIMAL:
       assert javaClass == BigDecimal.class;
-      return value == null
-          ? Expressions.constant(null)
-          : Expressions.new_(
-              BigDecimal.class,
-              Expressions.constant(value.toString()));
+      return Expressions.new_(BigDecimal.class,
+          Expressions.constant(value.toString()));
     case DATE:
-      value2 = value == null ? null
-          : (int) (((Calendar) value).getTimeInMillis() / MILLIS_IN_DAY);
+      value2 = (int) (((Calendar) value).getTimeInMillis() / MILLIS_IN_DAY);
+      javaClass = int.class;
       break;
     case TIME:
-      value2 = value == null ? null
-          : (int) (((Calendar) value).getTimeInMillis() % MILLIS_IN_DAY);
+      value2 = (int) (((Calendar) value).getTimeInMillis() % MILLIS_IN_DAY);
+      javaClass = int.class;
       break;
     case TIMESTAMP:
-      value2 = value == null ? null : ((Calendar) value).getTimeInMillis();
+      value2 = ((Calendar) value).getTimeInMillis();
+      javaClass = long.class;
       break;
     case INTERVAL_DAY_TIME:
-      if (value == null) {
-        value2 = null;
-        javaClass = Long.class;
-      } else {
-        value2 = ((BigDecimal) value).longValue();
-        javaClass = long.class;
-      }
+      value2 = ((BigDecimal) value).longValue();
+      javaClass = long.class;
       break;
     case INTERVAL_YEAR_MONTH:
-      if (value == null) {
-        value2 = null;
-        javaClass = Integer.class;
-      } else {
-        value2 = ((BigDecimal) value).intValue();
-        javaClass = int.class;
-      }
+      value2 = ((BigDecimal) value).intValue();
+      javaClass = int.class;
       break;
     case CHAR:
     case VARCHAR:
-      value2 = value == null ? null : ((NlsString) value).getValue();
+      value2 = ((NlsString) value).getValue();
       break;
     case BINARY:
     case VARBINARY:

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/aacbeb52/core/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java b/core/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
index 314d212..68a36df 100644
--- a/core/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
+++ b/core/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
@@ -925,6 +925,10 @@ public class SqlFunctions {
         : toInt(v, timeZone);
   }
 
+  public static long toLong(Date v) {
+    return toLong(v, LOCAL_TZ);
+  }
+
   public static int toInt(java.sql.Time v) {
     return (int) (toLong(v) % DateTimeUtil.MILLIS_PER_DAY);
   }

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/aacbeb52/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
index 292a2ef..b1a6cb8 100644
--- a/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
+++ b/core/src/test/java/net/hydromatic/optiq/test/JdbcTest.java
@@ -4195,6 +4195,11 @@ public class JdbcTest {
                   .withSchema("POST")
                   .connect();
             }
+            if (name.equals("catchall")) {
+              return OptiqAssert.that()
+                  .with("s", new ReflectiveSchemaTest.CatchallSchema())
+                  .connect();
+            }
             throw new RuntimeException("unknown connection '" + name + "'");
           }
         });

http://git-wip-us.apache.org/repos/asf/incubator-optiq/blob/aacbeb52/core/src/test/resources/sql/misc.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/misc.oq b/core/src/test/resources/sql/misc.oq
index bf2ee1e..7f4f31d 100644
--- a/core/src/test/resources/sql/misc.oq
+++ b/core/src/test/resources/sql/misc.oq
@@ -108,4 +108,62 @@ on ( d."deptno" + 2 - 2 = e."deptno" + 1 - 1  and e."deptno" + 10 - 10 = d."dept
 (3 rows)
 
 !ok
+
+# [OPTIQ-345] AssertionError in RexToLixTranslator comparing to date literal
+!use catchall
+select count(*) as c from "everyTypes" where "sqlDate" = DATE '1970-01-01';
++---+
+| C |
++---+
+| 1 |
++---+
+(1 row)
+
+!ok
+select count(*) as c from "everyTypes" where "sqlDate" = DATE '1971-02-03';
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+select count(*) as c from "everyTypes" where "sqlDate" > DATE '1970-01-01';
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+select count(*) as c from "everyTypes" where "sqlTime" = TIME '01:23:45';
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+select count(*) as c from "everyTypes" where "sqlTimestamp" = TIMESTAMP '1970-01-01 01:23:45';
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+select count(*) as c from "everyTypes" where "utilDate" = TIMESTAMP '1970-01-01 01:23:45';
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+
 # End misc.oq