calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcama...@apache.org
Subject calcite git commit: [CALCITE-1392] Druid default time column not properly recognized
Date Thu, 06 Oct 2016 07:04:31 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 73544eda3 -> a1e50b618


[CALCITE-1392] Druid default time column not properly recognized


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

Branch: refs/heads/master
Commit: a1e50b618d9ef011cb5b771b3a872bb69d93a361
Parents: 73544ed
Author: Jesus Camacho Rodriguez <jcamacho@apache.org>
Authored: Thu Oct 6 07:55:06 2016 +0100
Committer: Jesus Camacho Rodriguez <jcamacho@apache.org>
Committed: Thu Oct 6 07:55:06 2016 +0100

----------------------------------------------------------------------
 .../calcite/adapter/druid/DruidTable.java       | 15 ++++++++++----
 .../adapter/druid/DruidTableFactory.java        |  5 +----
 .../org/apache/calcite/test/DruidAdapterIT.java | 21 +++++++++++++++++++-
 3 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/a1e50b61/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java
index efdaa3d..8b4355f 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java
@@ -34,7 +34,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
 
 import org.joda.time.DateTime;
 import org.joda.time.Interval;
@@ -108,11 +107,19 @@ public class DruidTable extends AbstractTable implements TranslatableTable
{
     if (connection != null) {
       connection.metadata(dataSourceName, intervals, fieldMap, metricNameSet);
     }
+    if (timestampColumnName != null) {
+      // The default column has been added automatically if we retrieved
+      // the data source information with a segment metadata query. However,
+      // we can remove it since we declared explicitly a name for the
+      // timestamp column.
+      fieldMap.put(timestampColumnName, SqlTypeName.TIMESTAMP);
+      fieldMap.remove(DruidTable.DEFAULT_TIMESTAMP_COLUMN);
+    } else {
+      fieldMap.put(DruidTable.DEFAULT_TIMESTAMP_COLUMN, SqlTypeName.TIMESTAMP);
+      timestampColumnName = DruidTable.DEFAULT_TIMESTAMP_COLUMN;
+    }
     final ImmutableMap<String, SqlTypeName> fields =
         ImmutableMap.copyOf(fieldMap);
-    if (timestampColumnName == null) {
-      timestampColumnName = Iterables.get(fieldMap.keySet(), 0);
-    }
     return new DruidTable(druidSchema, dataSourceName,
         new MapRelProtoDataType(fields), ImmutableSet.copyOf(metricNameSet),
         timestampColumnName, intervals);

http://git-wip-us.apache.org/repos/asf/calcite/blob/a1e50b61/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTableFactory.java
----------------------------------------------------------------------
diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTableFactory.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTableFactory.java
index 46f5e04..f168f57 100644
--- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTableFactory.java
+++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTableFactory.java
@@ -51,7 +51,7 @@ public class DruidTableFactory implements TableFactory {
     // If "dataSource" operand is present it overrides the table name.
     final String dataSource = (String) operand.get("dataSource");
     final Set<String> metricNameBuilder = new LinkedHashSet<>();
-    String timestampColumnName = (String) operand.get("timestampColumn");
+    final String timestampColumnName = (String) operand.get("timestampColumn");
     final Map<String, SqlTypeName> fieldBuilder = new LinkedHashMap<>();
     final Object dimensionsRaw = operand.get("dimensions");
     if (dimensionsRaw instanceof List) {
@@ -90,9 +90,6 @@ public class DruidTableFactory implements TableFactory {
         metricNameBuilder.add(metricName);
       }
     }
-    if (timestampColumnName != null) {
-      fieldBuilder.put(timestampColumnName, SqlTypeName.TIMESTAMP);
-    }
     final String dataSourceName = Util.first(dataSource, name);
     DruidConnectionImpl c;
     if (dimensionsRaw == null || metricsRaw == null) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/a1e50b61/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 39b34ee..45defdc 100644
--- a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
+++ b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
@@ -132,7 +132,7 @@ public class DruidAdapterIT {
   @Test public void testSelectDistinctWikiNoColumns() {
     final String explain = "PLAN="
         + "EnumerableInterpreter\n"
-        + "  DruidQuery(table=[[wiki, wiki]], intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]],
filter=[=(CAST($18):VARCHAR(13) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\",
'Jeremy Corbyn')], groups=[{8}], aggs=[[]])\n";
+        + "  DruidQuery(table=[[wiki, wiki]], intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]],
filter=[=(CAST($16):VARCHAR(13) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\",
'Jeremy Corbyn')], groups=[{6}], aggs=[[]])\n";
     checkSelectDistinctWiki(WIKI_AUTO, "wiki")
         .explainContains(explain);
   }
@@ -164,6 +164,25 @@ public class DruidAdapterIT {
         .returnsUnordered("C=86829");
   }
 
+  @Test public void testSelectTimestampColumnNoTables() {
+    // Since columns are not explicitly declared, we use the default time
+    // column in the query.
+    final String sql = "select sum(\"added\")\n"
+        + "from \"wikiticker\"\n"
+        + "group by floor(\"__time\" to DAY)";
+    final String explain = "PLAN="
+            + "EnumerableInterpreter\n"
+            + "  BindableProject(EXPR$0=[$1])\n"
+            + "    DruidQuery(table=[[wiki, wikiticker]], intervals=[[1900-01-01T00:00:00.000Z/3000-01-01T00:00:00.000Z]],
projects=[[FLOOR($0, FLAG(DAY)), $1]], groups=[{0}], aggs=[[SUM($1)]])\n";
+    final String druidQuery = "{'queryType':'timeseries',"
+        + "'dataSource':'wikiticker','descending':false,'granularity':'DAY',"
+        + "'aggregations':[{'type':'longSum','name':'EXPR$0','fieldName':'added'}],"
+        + "'intervals':['1900-01-01T00:00:00.000Z/3000-01-01T00:00:00.000Z']}";
+    sql(sql, WIKI_AUTO2)
+        .explainContains(explain)
+        .queryContains(druidChecker(druidQuery));
+  }
+
   private CalciteAssert.AssertQuery checkSelectDistinctWiki(URL url, String tableName) {
     final String sql = "select distinct \"countryName\"\n"
         + "from \"" + tableName + "\"\n"


Mime
View raw message