calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [2/4] calcite git commit: [CALCITE-1770] Druid adapter: CAST(NULL AS ...) gives NPE (Slim Bouguerra)
Date Tue, 02 May 2017 06:43:00 GMT
[CALCITE-1770] Druid adapter: CAST(NULL AS ...) gives NPE (Slim Bouguerra)

Close apache/calcite#441


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

Branch: refs/heads/master
Commit: ef00738a053cbe881f2c840f3e3b5feeb010b6e1
Parents: 1aaa0d6
Author: Slim Bouguerra <slim.bouguerra@gmail.com>
Authored: Sat Apr 29 20:06:07 2017 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon May 1 16:07:50 2017 -0700

----------------------------------------------------------------------
 .../org/apache/calcite/adapter/druid/DruidQuery.java    |  4 ++++
 .../java/org/apache/calcite/test/DruidAdapterIT.java    | 12 ++++++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/ef00738a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
index 504e06d..81e94dd 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java
@@ -959,6 +959,10 @@ public class DruidQuery extends AbstractRelNode implements BindableRel
{
       case CAST:
         return tr(e, 0, set);
       case LITERAL:
+        if (((RexLiteral) e).getValue3() == null) {
+          // Druid considers null is equivalent to empty.
+          return "";
+        }
         return ((RexLiteral) e).getValue3().toString();
       case FLOOR:
       case EXTRACT:

http://git-wip-us.apache.org/repos/asf/calcite/blob/ef00738a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
----------------------------------------------------------------------
diff --git a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
index b903fbb..17d6211 100644
--- a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
+++ b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
@@ -2088,6 +2088,18 @@ public class DruidAdapterIT {
     sql(sql).explainContains(plan).queryContains(druidChecker("'queryType':'select'"))
         .returnsUnordered("EXPR$0=19");
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1770">[CALCITE-1770]
+   * Druid adapter: CAST(NULL AS ...) gives NPE</a>. */
+  @Test public void testPushCast() {
+    final String sql = "SELECT \"product_id\"\n"
+        + "from \"foodmart\"\n"
+        + "where \"product_id\" = cast(NULL as varchar)\n"
+        + "group by \"product_id\"";
+    String druidQuery = "'filter':{'type':'selector','dimension':'product_id','value':''}";
+    sql(sql).queryContains(druidChecker(druidQuery));
+  }
 }
 
 // End DruidAdapterIT.java


Mime
View raw message