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 2016/04/22 10:07:41 UTC

[12/13] calcite git commit: [CALCITE-1121] Druid adapter

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/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
new file mode 100644
index 0000000..42c3567
--- /dev/null
+++ b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
@@ -0,0 +1,643 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+import org.apache.calcite.adapter.druid.DruidQuery;
+import org.apache.calcite.util.Util;
+
+import com.google.common.base.Function;
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for the {@code org.apache.calcite.adapter.druid} package.
+ *
+ * <p>Before calling this test, you need to populate Druid, as follows:
+ *
+ * <blockquote><code>
+ * git clone https://github.com/vlsi/test-dataset
+ * cd test-dataset
+ * mvn install
+ * </code></blockquote>
+ *
+ * <p>This will create a virtual machine with Druid and test data set.
+ *
+ * <p>Features not yet implemented:
+ * <ul>
+ *   <li>push LIMIT into "select" query</li>
+ *   <li>push SORT and/or LIMIT into "groupBy" query</li>
+ *   <li>push HAVING into "groupBy" query</li>
+ * </ul>
+ */
+public class DruidAdapterIT {
+  /** Connection factory based on the "druid-foodmart" model. */
+  public static final ImmutableMap<String, String> FOODMART =
+      ImmutableMap.of("model",
+          DruidAdapterIT.class.getResource("/druid-foodmart-model.json")
+              .getPath());
+
+  /** Connection factory based on the "druid-wiki" model
+   * and the "wikiticker" data set. */
+  public static final ImmutableMap<String, String> WIKI =
+      ImmutableMap.of("model",
+          DruidAdapterIT.class.getResource("/druid-wiki-model.json")
+              .getPath());
+
+  /** Whether to run Druid tests. Enabled by default, however test is only
+   * included if "it" profile is activated ({@code -Pit}). To disable,
+   * specify {@code -Dcalcite.test.druid=false} on the Java command line. */
+  public static final boolean ENABLED =
+      Util.getBooleanProperty("calcite.test.druid", true);
+
+  /** Whether to run this test. */
+  protected boolean enabled() {
+    return ENABLED;
+  }
+
+  /** Returns a function that checks that a particular Druid query is
+   * generated to implement a query. */
+  private static Function<List, Void> druidChecker(final String... lines) {
+    return new Function<List, Void>() {
+      public Void apply(List list) {
+        assertThat(list.size(), is(1));
+        DruidQuery.QuerySpec querySpec = (DruidQuery.QuerySpec) list.get(0);
+        for (String line : lines) {
+          final String s = line.replace('\'', '"');
+          assertThat(querySpec.queryString, containsString(s));
+        }
+        return null;
+      }
+    };
+  }
+
+  /** Similar to {@link CalciteAssert#checkResultUnordered}, but filters strings
+   * before comparing them. */
+  static Function<ResultSet, Void> checkResultUnordered(
+      final String... lines) {
+    return new Function<ResultSet, Void>() {
+      public Void apply(ResultSet resultSet) {
+        try {
+          final List<String> expectedList = Lists.newArrayList(lines);
+          Collections.sort(expectedList);
+
+          final List<String> actualList = Lists.newArrayList();
+          CalciteAssert.toStringList(resultSet, actualList);
+          for (int i = 0; i < actualList.size(); i++) {
+            String s = actualList.get(i);
+            actualList.set(i,
+                s.replaceAll("\\.0;", ";").replaceAll("\\.0$", ""));
+          }
+          Collections.sort(actualList);
+
+          assertThat(actualList, equalTo(expectedList));
+          return null;
+        } catch (SQLException e) {
+          throw new RuntimeException(e);
+        }
+      }
+    };
+  }
+
+  /** Creates a query against the {@link #FOODMART} data set. */
+  private CalciteAssert.AssertQuery sql(String sql) {
+    return CalciteAssert.that()
+        .enable(enabled())
+        .with(FOODMART)
+        .query(sql);
+  }
+
+  /** Creates a query against the {@link #WIKI} data set. */
+  private CalciteAssert.AssertQuery wiki(String sql) {
+    return CalciteAssert.that()
+        .enable(enabled())
+        .with(WIKI)
+        .query(sql);
+  }
+
+  /** Tests a query against the {@link #WIKI} data set.
+   *
+   * <p>Most of the others in this suite are against {@link #FOODMART},
+   * but our examples in "druid-adapter.md" use wikiticker. */
+  @Test public void testSelectDistinctWiki() {
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[wiki, wiki]], filter=[=(CAST($12):VARCHAR(13) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'Jeremy Corbyn')], groups=[{4}], aggs=[[]])\n";
+    final String sql = "select distinct \"countryName\"\n"
+        + "from \"wiki\"\n"
+        + "where \"page\" = 'Jeremy Corbyn'";
+    final String druidQuery = "{'queryType':'groupBy',"
+        + "'dataSource':'wikiticker','granularity':'all',"
+        + "'dimensions':['countryName'],"
+        + "'filter':{'type':'selector','dimension':'page','value':'Jeremy Corbyn'},"
+        + "'aggregations':[{'type':'longSum','name':'unit_sales','fieldName':'unit_sales'}],"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z']}";
+    wiki(sql)
+        .returnsUnordered("countryName=United Kingdom",
+            "countryName=null")
+        .explainContains(explain)
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Test public void testSelectDistinct() {
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[foodmart, foodmart]], groups=[{29}], aggs=[[]])";
+    final String sql = "select distinct \"state_province\" from \"foodmart\"";
+    final String druidQuery = "{'queryType':'groupBy','dataSource':'foodmart','granularity':'all',"
+        + "'dimensions':['state_province'],"
+        + "'aggregations':[{'type':'longSum','name':'unit_sales','fieldName':'unit_sales'}],"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z']}";
+    sql(sql)
+        .returnsUnordered("state_province=CA",
+            "state_province=OR",
+            "state_province=WA")
+        .explainContains(explain)
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Ignore("TODO: fix invalid cast from Integer to Long")
+  @Test public void testSelectGroupBySum() {
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[foodmart, foodmart]], projects=[[$29, CAST($88):INTEGER]], groups=[{0}], aggs=[[SUM($1)]])";
+    final String sql = "select \"state_province\", sum(cast(\"unit_sales\" as integer)) as u\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\"";
+    sql(sql)
+        .returnsUnordered("state_province=CA; U=74748",
+            "state_province=OR; U=67659",
+            "state_province=WA; U=124366")
+        .explainContains(explain);
+  }
+
+  @Test public void testSort() {
+    // Note: We do not push down SORT yet
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[DESC])\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], projects=[[$38, $29]], groups=[{0, 1}], aggs=[[]])";
+    final String sql = "select distinct \"gender\", \"state_province\"\n"
+        + "from \"foodmart\" order by 2, 1 desc";
+    sql(sql)
+        .returnsOrdered("gender=M; state_province=CA",
+            "gender=F; state_province=CA",
+            "gender=M; state_province=OR",
+            "gender=F; state_province=OR",
+            "gender=M; state_province=WA",
+            "gender=F; state_province=WA")
+        .explainContains(explain);
+  }
+
+  @Test public void testSortLimit() {
+    // Note: We do not push down SORT-LIMIT into Druid "groupBy" query yet
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[DESC], offset=[2], fetch=[3])\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], projects=[[$38, $29]], groups=[{0, 1}], aggs=[[]])";
+    final String sql = "select distinct \"gender\", \"state_province\"\n"
+        + "from \"foodmart\"\n"
+        + "order by 2, 1 desc offset 2 rows fetch next 3 rows only";
+    sql(sql)
+        .returnsOrdered("gender=M; state_province=OR",
+            "gender=F; state_province=OR",
+            "gender=M; state_province=WA")
+        .explainContains(explain);
+  }
+
+  @Test public void testOffsetLimit() {
+    // We do not yet push LIMIT into a Druid "select" query as a "threshold".
+    // It is not possible to push OFFSET into Druid "select" query.
+    final String sql = "select \"state_province\", \"product_name\"\n"
+        + "from \"foodmart\"\n"
+        + "offset 2 fetch next 3 rows only";
+    final String druidQuery = "{'queryType':'select','dataSource':'foodmart',"
+        + "'descending':'false','intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'dimensions':['state_province','product_name'],'metrics':[],'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}}";
+    sql(sql)
+        .runs()
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Test public void testLimit() {
+    // We do not yet push LIMIT into a Druid "select" query as a "threshold".
+    final String sql = "select \"gender\", \"state_province\"\n"
+        + "from \"foodmart\" fetch next 3 rows only";
+    final String druidQuery = "{'queryType':'select','dataSource':'foodmart',"
+        + "'descending':'false','intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'dimensions':['gender','state_province'],'metrics':[],'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}";
+    sql(sql)
+        .runs()
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Test public void testGroupByLimit() {
+    // We do not yet push LIMIT into a Druid "groupBy" query.
+    final String sql = "select distinct \"gender\", \"state_province\"\n"
+        + "from \"foodmart\" fetch next 3 rows only";
+    final String druidQuery = "{'queryType':'groupBy','dataSource':'foodmart',"
+        + "'granularity':'all','dimensions':['gender','state_province'],"
+        + "'aggregations':[{'type':'longSum','name':'unit_sales','fieldName':'unit_sales'}],"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z']}";
+    final String explain = "PLAN="
+        + "EnumerableLimit(fetch=[3])\n"
+        + "  EnumerableInterpreter\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], projects=[[$38, $29]], groups=[{0, 1}], aggs=[[]])";
+    sql(sql)
+        .runs()
+        .explainContains(explain)
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  /** Tests a query that contains no GROUP BY and is therefore executed as a
+   * Druid "select" query. */
+  @Test public void testFilterSortDesc() {
+    final String sql = "select * from \"foodmart\"\n"
+        + "where \"product_id\" BETWEEN 1500 AND 1502\n"
+        + "order by \"state_province\" desc, \"product_id\"";
+    final String druidQuery = "{'queryType':'select','dataSource':'foodmart',"
+        + "'descending':'false','intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'filter':{'type':'and','fields':["
+        + "{'type':'bound','dimension':'product_id','lower':'1500','lowerStrict':false,'alphaNumeric':false},"
+        + "{'type':'bound','dimension':'product_id','upper':'1502','upperStrict':false,'alphaNumeric':false}]},"
+        + "'dimensions':[],'metrics':[],'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}}";
+    sql(sql)
+        .limit(4)
+        .returns(
+            new Function<ResultSet, Void>() {
+              public Void apply(ResultSet resultSet) {
+                try {
+                  for (int i = 0; i < 4; i++) {
+                    assertTrue(resultSet.next());
+                    assertThat(resultSet.getString("product_name"),
+                        is("Fort West Dried Apricots"));
+                  }
+                  assertFalse(resultSet.next());
+                  return null;
+                } catch (SQLException e) {
+                  throw Throwables.propagate(e);
+                }
+              }
+            })
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  /** Tests a query whose filter removes all rows. */
+  @Test public void testFilterOutEverything() {
+    final String sql = "select * from \"foodmart\"\n"
+        + "where \"product_id\" = -1";
+    final String druidQuery = "{'queryType':'select','dataSource':'foodmart',"
+        + "'descending':'false','intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'filter':{'type':'selector','dimension':'product_id','value':'-1'},"
+        + "'dimensions':[],'metrics':[],'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}}";
+    sql(sql)
+        .limit(4)
+        .returnsUnordered()
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  /** As {@link #testFilterSortDesc} but with a filter that cannot be pushed
+   * down to Druid. */
+  @Test public void testNonPushableFilterSortDesc() {
+    final String sql = "select * from \"foodmart\"\n"
+        + "where cast(\"product_id\" as integer) - 1500 BETWEEN 0 AND 2\n"
+        + "order by \"state_province\" desc, \"product_id\"";
+    final String druidQuery = "{'queryType':'select','dataSource':'foodmart',"
+        + "'descending':'false','intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'dimensions':[],'metrics':[],'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}}";
+    sql(sql)
+        .limit(4)
+        .returns(
+            new Function<ResultSet, Void>() {
+              public Void apply(ResultSet resultSet) {
+                try {
+                  for (int i = 0; i < 4; i++) {
+                    assertTrue(resultSet.next());
+                    assertThat(resultSet.getString("product_name"),
+                        is("Fort West Dried Apricots"));
+                  }
+                  assertFalse(resultSet.next());
+                  return null;
+                } catch (SQLException e) {
+                  throw Throwables.propagate(e);
+                }
+              }
+            })
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Test public void testUnionPlan() {
+    final String sql = "select distinct \"gender\" from \"foodmart\"\n"
+        + "union all\n"
+        + "select distinct \"marital_status\" from \"foodmart\"";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableUnion(all=[true])\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], groups=[{38}], aggs=[[]])\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], groups=[{36}], aggs=[[]])";
+    sql(sql)
+        .explainContains(explain)
+        .returnsUnordered(
+            "gender=F",
+            "gender=M",
+            "gender=M",
+            "gender=S");
+  }
+
+  @Test public void testFilterUnionPlan() {
+    final String sql = "select * from (\n"
+        + "  select distinct \"gender\" from \"foodmart\"\n"
+        + "  union all\n"
+        + "  select distinct \"marital_status\" from \"foodmart\")\n"
+        + "where \"gender\" = 'M'";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableFilter(condition=[=($0, 'M')])\n"
+        + "    BindableUnion(all=[true])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], groups=[{38}], aggs=[[]])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], groups=[{36}], aggs=[[]])";
+    sql(sql)
+        .explainContains(explain)
+        .returnsUnordered("gender=M",
+            "gender=M");
+  }
+
+  @Test public void testCountGroupByEmpty() {
+    final String druidQuery = "{'queryType':'groupBy','dataSource':'foodmart','granularity':'all',"
+        + "'dimensions':[],"
+        + "'aggregations':[{'type':'count','name':'EXPR$0'}],"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z']}";
+    final String explain = "PLAN=EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[foodmart, foodmart]], projects=[[]], groups=[{}], aggs=[[COUNT()]])";
+    final String sql = "select count(*) from \"foodmart\"";
+    sql(sql)
+        .returns("EXPR$0=86829\n")
+        .queryContains(druidChecker(druidQuery))
+        .explainContains(explain);
+  }
+
+  @Test public void testGroupByOneColumnNotProjected() {
+    final String sql = "select count(*) as c from \"foodmart\"\n"
+        + "group by \"state_province\" order by 1";
+    sql(sql)
+        .returnsOrdered("C=21610",
+            "C=24441",
+            "C=40778");
+  }
+
+  @Test public void testOrderByOneColumnNotProjected() {
+    // Result including state: CA=24441, OR=21610, WA=40778
+    final String sql = "select count(*) as c from \"foodmart\"\n"
+        + "group by \"state_province\" order by \"state_province\"";
+    sql(sql)
+        .returnsOrdered("C=24441",
+            "C=21610",
+            "C=40778");
+  }
+
+  @Test public void testGroupByOneColumn() {
+    final String sql = "select \"state_province\", count(*) as c\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\"\n"
+        + "order by \"state_province\"";
+    String explain = "PLAN=EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$0], dir0=[ASC])\n"
+        + "    DruidQuery(table=[[foodmart, foodmart]], groups=[{29}], aggs=[[COUNT()]])";
+    sql(sql)
+        .limit(2)
+        .returnsOrdered("state_province=CA; C=24441",
+            "state_province=OR; C=21610")
+        .explainContains(explain);
+  }
+
+  @Test public void testGroupByOneColumnReversed() {
+    final String sql = "select count(*) as c, \"state_province\"\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\"\n"
+        + "order by \"state_province\"";
+    sql(sql)
+        .limit(2)
+        .returnsOrdered("C=24441; state_province=CA",
+            "C=21610; state_province=OR");
+  }
+
+  @Ignore("TODO: fix invalid cast from Integer to Long")
+  @Test public void testGroupByAvgSumCount() {
+    final String sql = "select \"state_province\",\n"
+        + " avg(\"unit_sales\") as a,\n"
+        + " sum(\"unit_sales\") as s,\n"
+        + " count(\"store_sqft\") as c,\n"
+        + " count(*) as c0\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\"\n"
+        + "order by 1";
+    String druidQuery = "'aggregations':["
+        + "{'type':'longSum','name':'$f1','fieldName':'unit_sales'},"
+        + "{'type':'count','name':'$f2'}]";
+    sql(sql)
+        .limit(2)
+        .returnsUnordered("state_province=CA; A=3; S=74748; C=23190; C0=23190",
+            "state_province=OR; A=3; S=67659; C=19027; C0=19027")
+        .queryContains(druidChecker(druidQuery));
+  }
+
+  @Test public void testGroupByHaving() {
+    // Note: We don't push down HAVING yet
+    final String sql = "select \"state_province\" as s, count(*) as c\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\" having count(*) > 23000 order by 1";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$0], dir0=[ASC])\n"
+        + "    BindableFilter(condition=[>($1, 23000)])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], groups=[{29}], aggs=[[COUNT()]])";
+    sql(sql)
+        .returnsOrdered("S=CA; C=24441",
+            "S=WA; C=40778")
+        .explainContains(explain);
+  }
+
+  @Test public void testGroupComposite() {
+    // Note: We don't push down SORT-LIMIT yet
+    final String sql = "select count(*) as c, \"state_province\", \"city\"\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\", \"city\"\n"
+        + "order by c desc limit 2";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$0], dir0=[DESC], fetch=[2])\n"
+        + "    BindableProject(C=[$2], state_province=[$1], city=[$0])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], groups=[{28, 29}], aggs=[[COUNT()]])";
+    sql(sql)
+        .returnsOrdered("C=7394; state_province=WA; city=Spokane",
+            "C=3958; state_province=WA; city=Olympia")
+        .explainContains(explain);
+  }
+
+  /** Tests that distinct-count is pushed down to Druid and evaluated using
+   * "cardinality". The result is approximate, but gives the correct result in
+   * this example when rounded down using FLOOR. */
+  @Test public void testDistinctCount() {
+    final String sql = "select \"state_province\",\n"
+        + " floor(count(distinct \"city\")) as cdc\n"
+        + "from \"foodmart\"\n"
+        + "group by \"state_province\"\n"
+        + "order by 2 desc limit 2";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableSort(sort0=[$1], dir0=[DESC], fetch=[2])\n"
+        + "    BindableProject(state_province=[$0], CDC=[FLOOR($1)])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], groups=[{29}], aggs=[[COUNT(DISTINCT $28)]])";
+    sql(sql)
+        .explainContains(explain)
+        .returnsUnordered("state_province=CA; CDC=45",
+            "state_province=WA; CDC=22");
+  }
+
+  /** Tests that projections of columns are pushed into the DruidQuery, and
+   * projections of expressions that Druid cannot handle (in this case, a
+   * literal 0) stay up. */
+  @Test public void testProject() {
+    final String sql = "select \"product_name\", 0 as zero\n"
+        + "from \"foodmart\"\n"
+        + "order by \"product_name\"";
+    final String explain = "PLAN="
+        + "EnumerableInterpreter\n"
+        + "  BindableProject(product_name=[$0], ZERO=[0])\n"
+        + "    BindableSort(sort0=[$0], dir0=[ASC])\n"
+        + "      DruidQuery(table=[[foodmart, foodmart]], projects=[[$2]])";
+    sql(sql)
+        .limit(2)
+        .explainContains(explain)
+        .returnsUnordered("product_name=ADJ Rosy Sunglasses; ZERO=0",
+            "product_name=ADJ Rosy Sunglasses; ZERO=0");
+  }
+
+  @Test public void testFilterDistinct() {
+    final String sql = "select distinct \"state_province\", \"city\",\n"
+        + "  \"product_name\"\n"
+        + "from \"foodmart\"\n"
+        + "where \"product_name\" = 'High Top Dried Mushrooms'\n"
+        + "and \"quarter\" in ('Q2', 'Q3')\n"
+        + "and \"state_province\" = 'WA'";
+    final String druidQuery = "{'queryType':'groupBy',"
+        + "'dataSource':'foodmart',"
+        + "'granularity':'all',"
+        + "'dimensions':['state_province','city','product_name'],"
+        + "'filter':{'type':'and','fields':["
+        + "{'type':'selector','dimension':'product_name','value':'High Top Dried Mushrooms'},"
+        + "{'type':'or','fields':["
+        + "{'type':'selector','dimension':'quarter','value':'Q2'},"
+        + "{'type':'selector','dimension':'quarter','value':'Q3'}]},"
+        + "{'type':'selector','dimension':'state_province','value':'WA'}]},"
+        + "'aggregations':[{'type':'longSum','name':'unit_sales','fieldName':'unit_sales'}],"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z']}";
+    final String explain = "PLAN=EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[foodmart, foodmart]],"
+        + " filter=[AND(=(CAST($2):VARCHAR(24) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'High Top Dried Mushrooms'),"
+        + " OR(=($86, CAST('Q2'):VARCHAR(1) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL),"
+        + " =($86, CAST('Q3'):VARCHAR(1) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL)),"
+        + " =(CAST($29):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'WA'))],"
+        + " projects=[[$29, $28, $2]], groups=[{0, 1, 2}], aggs=[[]])\n";
+    sql(sql)
+        .queryContains(druidChecker(druidQuery))
+        .explainContains(explain)
+        .returnsUnordered(
+            "state_province=WA; city=Bremerton; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Everett; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Kirkland; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Lynnwood; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Olympia; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Port Orchard; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Puyallup; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Spokane; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Tacoma; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Yakima; product_name=High Top Dried Mushrooms");
+  }
+
+  @Test public void testFilter() {
+    final String sql = "select \"state_province\", \"city\",\n"
+        + "  \"product_name\"\n"
+        + "from \"foodmart\"\n"
+        + "where \"product_name\" = 'High Top Dried Mushrooms'\n"
+        + "and \"quarter\" in ('Q2', 'Q3')\n"
+        + "and \"state_province\" = 'WA'";
+    final String druidQuery = "{'queryType':'select',"
+        + "'dataSource':'foodmart',"
+        + "'descending':'false',"
+        + "'intervals':['1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z'],"
+        + "'filter':{'type':'and','fields':["
+        + "{'type':'selector','dimension':'product_name','value':'High Top Dried Mushrooms'},"
+        + "{'type':'or','fields':["
+        + "{'type':'selector','dimension':'quarter','value':'Q2'},"
+        + "{'type':'selector','dimension':'quarter','value':'Q3'}]},"
+        + "{'type':'selector','dimension':'state_province','value':'WA'}]},"
+        + "'dimensions':['state_province','city','product_name'],"
+        + "'metrics':[],"
+        + "'granularity':'all',"
+        + "'pagingSpec':{'threshold':16384}}";
+    final String explain = "PLAN=EnumerableInterpreter\n"
+        + "  DruidQuery(table=[[foodmart, foodmart]],"
+        + " filter=[AND(=(CAST($2):VARCHAR(24) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'High Top Dried Mushrooms'),"
+        + " OR(=($86, CAST('Q2'):VARCHAR(1) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL),"
+        + " =($86, CAST('Q3'):VARCHAR(1) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL)),"
+        + " =(CAST($29):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'WA'))],"
+        + " projects=[[$29, $28, $2]])\n";
+    sql(sql)
+        .queryContains(druidChecker(druidQuery))
+        .explainContains(explain)
+        .returnsUnordered(
+            "state_province=WA; city=Bremerton; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Bremerton; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Everett; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Kirkland; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Lynnwood; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Olympia; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Port Orchard; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Puyallup; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Puyallup; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Spokane; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Spokane; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Spokane; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Tacoma; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Yakima; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Yakima; product_name=High Top Dried Mushrooms",
+            "state_province=WA; city=Yakima; product_name=High Top Dried Mushrooms");
+  }
+}
+
+// End DruidAdapterIT.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/druid/src/test/resources/druid-foodmart-model.json
----------------------------------------------------------------------
diff --git a/druid/src/test/resources/druid-foodmart-model.json b/druid/src/test/resources/druid-foodmart-model.json
new file mode 100644
index 0000000..68102f0
--- /dev/null
+++ b/druid/src/test/resources/druid-foodmart-model.json
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+{
+  "version": "1.0",
+  "defaultSchema": "foodmart",
+  "schemas": [
+    {
+      "type": "custom",
+      "name": "foodmart",
+      "factory": "org.apache.calcite.adapter.druid.DruidSchemaFactory",
+      "operand": {
+        "url": "http://localhost:8082/druid/v2/?pretty"
+      },
+      "tables": [
+        {
+          "name": "foodmart",
+          "factory": "org.apache.calcite.adapter.druid.DruidTableFactory",
+          "operand": {
+            "interval": "1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z",
+            "timestampColumn": "the_date",
+            "dimensions": [
+              "product_id",
+              "brand_name",
+              "product_name",
+              "SKU",
+              "SRP",
+              "gross_weight",
+              "net_weight",
+              "recyclable_package",
+              "low_fat",
+              "units_per_case",
+              "cases_per_pallet",
+              "shelf_width",
+              "shelf_height",
+              "shelf_depth",
+              "product_class_id",
+              "product_subcategory",
+              "product_category",
+              "product_department",
+              "product_family",
+              "customer_id",
+              "account_num",
+              "lname",
+              "fname",
+              "mi",
+              "address1",
+              "address2",
+              "address3",
+              "address4",
+              "city",
+              "state_province",
+              "postal_code",
+              "country",
+              "customer_region_id",
+              "phone1",
+              "phone2",
+              "birthdate",
+              "marital_status",
+              "yearly_income",
+              "gender",
+              "total_children",
+              "num_children_at_home",
+              "education",
+              "date_accnt_opened",
+              "member_card",
+              "occupation",
+              "houseowner",
+              "num_cars_owned",
+              "fullname",
+              "promotion_id",
+              "promotion_district_id",
+              "promotion_name",
+              "media_type",
+              "cost",
+              "start_date",
+              "end_date",
+              "store_id",
+              "store_type",
+              "region_id",
+              "store_name",
+              "store_number",
+              "store_street_address",
+              "store_city",
+              "store_state",
+              "store_postal_code",
+              "store_country",
+              "store_manager",
+              "store_phone",
+              "store_fax",
+              "first_opened_date",
+              "last_remodel_date",
+              "store_sqft",
+              "grocery_sqft",
+              "frozen_sqft",
+              "meat_sqft",
+              "coffee_bar",
+              "video_store",
+              "salad_bar",
+              "prepared_food",
+              "florist",
+              "time_id",
+              "the_day",
+              "the_month",
+              "the_year",
+              "day_of_month",
+              "week_of_year",
+              "month_of_year",
+              "quarter",
+              "fiscal_period"
+            ],
+            "metrics": [
+              "unit_sales",
+              {
+                "name": "store_sales",
+                "type": "double"
+              },
+              {
+                "name": "store_cost",
+                "type": "double"
+              }
+            ]
+          }
+        }
+      ]
+    }
+  ]
+}

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/druid/src/test/resources/druid-wiki-model.json
----------------------------------------------------------------------
diff --git a/druid/src/test/resources/druid-wiki-model.json b/druid/src/test/resources/druid-wiki-model.json
new file mode 100644
index 0000000..eb13494
--- /dev/null
+++ b/druid/src/test/resources/druid-wiki-model.json
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+{
+  "version": "1.0",
+  "defaultSchema": "wiki",
+  "schemas": [
+    {
+      "type": "custom",
+      "name": "wiki",
+      "factory": "org.apache.calcite.adapter.druid.DruidSchemaFactory",
+      "operand": {
+        "url": "http://localhost:8082/druid/v2/?pretty"
+      },
+      "tables": [
+        {
+          "name": "wiki",
+          "factory": "org.apache.calcite.adapter.druid.DruidTableFactory",
+          "operand": {
+            "dataSource": "wikiticker",
+            "interval": "1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z",
+            "timestampColumn": "time",
+            "dimensions": [
+              "channel",
+              "cityName",
+              "comment",
+              "countryIsoCode",
+              "countryName",
+              "isAnonymous",
+              "isMinor",
+              "isNew",
+              "isRobot",
+              "isUnpatrolled",
+              "metroCode",
+              "namespace",
+              "page",
+              "regionIsoCode",
+              "regionName",
+              "user"
+            ],
+            "metrics": [
+              {
+                "name" : "count",
+                "type" : "count"
+              },
+              {
+                "name" : "added",
+                "type" : "longSum",
+                "fieldName" : "added"
+              },
+              {
+                "name" : "deleted",
+                "type" : "longSum",
+                "fieldName" : "deleted"
+              },
+              {
+                "name" : "delta",
+                "type" : "longSum",
+                "fieldName" : "delta"
+              },
+              {
+                "name" : "user_unique",
+                "type" : "hyperUnique",
+                "fieldName" : "user"
+              }
+            ]
+          }
+        }
+      ]
+    }
+  ]
+}

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/druid/src/test/resources/foodmart-schema.spec
----------------------------------------------------------------------
diff --git a/druid/src/test/resources/foodmart-schema.spec b/druid/src/test/resources/foodmart-schema.spec
new file mode 100644
index 0000000..5531214
--- /dev/null
+++ b/druid/src/test/resources/foodmart-schema.spec
@@ -0,0 +1,73 @@
+[
+  {
+    "dataSchema": {
+      "dataSource": "foodmart",
+      "parser": {
+        "parseSpec": {
+          "format": "json",
+          "timestampSpec": {
+            "column": "the_date",
+            "format": "iso"
+          },
+          "dimensionsSpec": {
+            "dimensions": [
+              "gender",
+              "country",
+              "state_province"
+            ],
+            "dimensionExclusions": [
+
+            ],
+            "spatialDimensions": [
+            ]
+          }
+        }
+      },
+      "metricsSpec": [
+        {
+          "name": "sales",
+          "type": "count"
+        },
+        {
+          "fieldName": "unit_sales",
+          "name": "unit_sales",
+          "type": "doubleSum"
+        },
+        {
+          "fieldName": "store_sales",
+          "name": "store_sales",
+          "type": "doubleSum"
+        }
+      ],
+      "granularitySpec": {
+        "type": "uniform",
+        "segmentGranularity": "DAY",
+        "queryGranularity": "NONE"
+      }
+    },
+    "ioConfig": {
+      "type": "realtime",
+      "firehose": {
+        "type": "local",
+        "filter": "*.json",
+        "baseDir": "foodmart/data"
+      },
+      "plumber": {
+        "type": "realtime",
+        "rejectionPolicy": {
+          "type": "test"
+         }
+      }
+    },
+    "tuningConfig": {
+        "type" : "realtime",
+        "maxRowsInMemory": 500000,
+        "intermediatePersistPeriod": "P10000d",
+        "windowPeriod": "P10000d",
+        "basePersistDirectory": "\/tmp\/realtime\/basePersist",
+        "rejectionPolicy": {
+            "type": "serverTime"
+        }
+    }
+  }
+]

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/druid/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/druid/src/test/resources/log4j.properties b/druid/src/test/resources/log4j.properties
new file mode 100644
index 0000000..65a3982
--- /dev/null
+++ b/druid/src/test/resources/log4j.properties
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to you under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Root logger is configured at INFO and is sent to A1
+log4j.rootLogger=INFO, A1
+
+# A1 goes to the console
+#log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+log4j.appender.A1=org.apache.log4j.RollingFileAppender
+log4j.appender.A1.File=/tmp/trace.log
+
+
+# Set the pattern for each log message
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p - %m%n

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c854151..b12e430 100644
--- a/pom.xml
+++ b/pom.xml
@@ -130,6 +130,7 @@ limitations under the License.
   <modules>
     <module>cassandra</module>
     <module>core</module>
+    <module>druid</module>
     <module>example</module>
     <module>linq4j</module>
     <module>mongodb</module>

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/site/_docs/adapter.md
----------------------------------------------------------------------
diff --git a/site/_docs/adapter.md b/site/_docs/adapter.md
index 93ea1c9..7805333 100644
--- a/site/_docs/adapter.md
+++ b/site/_docs/adapter.md
@@ -27,8 +27,9 @@ limitations under the License.
 A schema adapter allows Calcite to read particular kind of data,
 presenting the data as tables within a schema.
 
-* [Cassandra adapter](cassandra.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/cassandra/package-summary.html">calcite-cassandra</a>)
+* [Cassandra adapter](cassandra_adapter.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/cassandra/package-summary.html">calcite-cassandra</a>)
 * CSV adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/csv/package-summary.html">example/csv</a>)
+* [Druid adapter](druid_adapter.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/druid/package-summary.html">calcite-druid</a>)
 * JDBC adapter (part of <a href="{{ site.apiRoot }}/org/apache/calcite/adapter/jdbc/package-summary.html">calcite-core</a>)
 * MongoDB adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/mongodb/package-summary.html">calcite-mongodb</a>)
 * Spark adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/spark/package-summary.html">calcite-spark</a>)

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/site/_docs/cassandra.md
----------------------------------------------------------------------
diff --git a/site/_docs/cassandra.md b/site/_docs/cassandra.md
deleted file mode 100644
index 58a139c..0000000
--- a/site/_docs/cassandra.md
+++ /dev/null
@@ -1,110 +0,0 @@
----
-layout: docs
-title: Cassandra adapter
-permalink: /docs/cassandra.html
----
-<!--
-{% comment %}
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to you under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-{% endcomment %}
--->
-
-For instructions on downloading and building Calcite, start with the
-[tutorial]({{ site.baseurl }}/docs/tutorial.html).
-
-Once you've managed to compile the project, you can return here to
-start querying Cassandra with Calcite.  First, we need a
-[model definition]({{ site.baseurl }}/docs/model.html).
-The model gives Calcite the necessary parameters to create an instance
-of the Cassandra adapter. Note that while models can contain
-definitions of
-[materializations]({{ site.baseurl }}/docs/model.html#materialization),
-the adapter will attempt to automatically populate any materialized views
-[defined in Cassandra](http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views).
-
-A basic example of a model file is given below:
-
-{% highlight json %}
-{
-  version: '1.0',
-  defaultSchema: 'twissandra',
-  schemas: [
-    {
-      name: 'twissandra',
-      type: 'custom',
-      factory: 'org.apache.calcite.adapter.cassandra.CassandraSchemaFactory',
-      operand: {
-        host: 'localhost',
-        keyspace: 'twissandra'
-      }
-    }
-  ]
-}
-{% endhighlight %}
-
-Assuming this file is stored as `model.json`, you can connect to
-Cassandra via [`sqlline`](https://github.com/julianhyde/sqlline) as
-follows:
-
-{% highlight bash %}
-$ ./sqlline
-sqlline> !connect jdbc:calcite:model=model.json admin admin
-{% endhighlight %}
-
-`sqlline` will now accept SQL queries which access your CQL tables.
-However, you're not restricted to issuing queries supported by
-[CQL](https://cassandra.apache.org/doc/cql3/CQL-2.2.html).
-Calcite allows you to perform complex operations such as aggregations
-or joins. The adapter will attempt to compile the query into the most
-efficient CQL possible by exploiting filtering and sorting directly in
-Cassandra where possible.
-
-For example, in the example dataset there is a CQL table named `timeline`
-with `username` as the partition key and `time` as the clustering key.
-
-We can issue a simple query to fetch the most recent tweet ID of the
-user by writing standard SQL:
-
-{% highlight sql %}
-sqlline> SELECT "tweet_id"
-         FROM "timeline"
-         WHERE "username" = 'JmuhsAaMdw'
-         ORDER BY "time" DESC LIMIT 1;
-+--------------------------------------+
-| tweet_id                             |
-+--------------------------------------+
-| f3d3d4dc-d05b-11e5-b58b-90e2ba530b12 |
-+--------------------------------------+
-{% endhighlight %}
-
-While executing this query, the Cassandra adapter is able to recognize
-that `username` is the partition key and can be filtered by Cassandra.
-It also recognizes the clustering key `time` and pushes the ordering to
-Cassandra as well.
-
-The final CQL query given to Cassandra is below:
-
-{% highlight sql %}
-SELECT username, time, tweet_id
-FROM "timeline"
-WHERE username = 'JmuhsAaMdw'
-ORDER BY time DESC ALLOW FILTERING;
-{% endhighlight %}
-
-There is still significant work to do in improving the flexibility and
-performance of the adapter, but if you're looking for a quick way to
-gain additional insights into data stored in Cassandra, Calcite should
-prove useful.

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/site/_docs/cassandra_adapter.md
----------------------------------------------------------------------
diff --git a/site/_docs/cassandra_adapter.md b/site/_docs/cassandra_adapter.md
new file mode 100644
index 0000000..f8da6c0
--- /dev/null
+++ b/site/_docs/cassandra_adapter.md
@@ -0,0 +1,110 @@
+---
+layout: docs
+title: Cassandra adapter
+permalink: /docs/cassandra_adapter.html
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+For instructions on downloading and building Calcite, start with the
+[tutorial]({{ site.baseurl }}/docs/tutorial.html).
+
+Once you've managed to compile the project, you can return here to
+start querying Cassandra with Calcite.  First, we need a
+[model definition]({{ site.baseurl }}/docs/model.html).
+The model gives Calcite the necessary parameters to create an instance
+of the Cassandra adapter. Note that while models can contain
+definitions of
+[materializations]({{ site.baseurl }}/docs/model.html#materialization),
+the adapter will attempt to automatically populate any materialized views
+[defined in Cassandra](http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views).
+
+A basic example of a model file is given below:
+
+{% highlight json %}
+{
+  version: '1.0',
+  defaultSchema: 'twissandra',
+  schemas: [
+    {
+      name: 'twissandra',
+      type: 'custom',
+      factory: 'org.apache.calcite.adapter.cassandra.CassandraSchemaFactory',
+      operand: {
+        host: 'localhost',
+        keyspace: 'twissandra'
+      }
+    }
+  ]
+}
+{% endhighlight %}
+
+Assuming this file is stored as `model.json`, you can connect to
+Cassandra via [`sqlline`](https://github.com/julianhyde/sqlline) as
+follows:
+
+{% highlight bash %}
+$ ./sqlline
+sqlline> !connect jdbc:calcite:model=model.json admin admin
+{% endhighlight %}
+
+`sqlline` will now accept SQL queries which access your CQL tables.
+However, you're not restricted to issuing queries supported by
+[CQL](https://cassandra.apache.org/doc/cql3/CQL-2.2.html).
+Calcite allows you to perform complex operations such as aggregations
+or joins. The adapter will attempt to compile the query into the most
+efficient CQL possible by exploiting filtering and sorting directly in
+Cassandra where possible.
+
+For example, in the example dataset there is a CQL table named `timeline`
+with `username` as the partition key and `time` as the clustering key.
+
+We can issue a simple query to fetch the most recent tweet ID of the
+user by writing standard SQL:
+
+{% highlight sql %}
+sqlline> SELECT "tweet_id"
+         FROM "timeline"
+         WHERE "username" = 'JmuhsAaMdw'
+         ORDER BY "time" DESC LIMIT 1;
++--------------------------------------+
+| tweet_id                             |
++--------------------------------------+
+| f3d3d4dc-d05b-11e5-b58b-90e2ba530b12 |
++--------------------------------------+
+{% endhighlight %}
+
+While executing this query, the Cassandra adapter is able to recognize
+that `username` is the partition key and can be filtered by Cassandra.
+It also recognizes the clustering key `time` and pushes the ordering to
+Cassandra as well.
+
+The final CQL query given to Cassandra is below:
+
+{% highlight sql %}
+SELECT username, time, tweet_id
+FROM "timeline"
+WHERE username = 'JmuhsAaMdw'
+ORDER BY time DESC ALLOW FILTERING;
+{% endhighlight %}
+
+There is still significant work to do in improving the flexibility and
+performance of the adapter, but if you're looking for a quick way to
+gain additional insights into data stored in Cassandra, Calcite should
+prove useful.

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/site/_docs/druid_adapter.md
----------------------------------------------------------------------
diff --git a/site/_docs/druid_adapter.md b/site/_docs/druid_adapter.md
new file mode 100644
index 0000000..3a330a6
--- /dev/null
+++ b/site/_docs/druid_adapter.md
@@ -0,0 +1,174 @@
+---
+layout: docs
+title: Druid adapter
+permalink: /docs/druid_adapter.html
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+[Druid](http://druid.io/) is a fast column-oriented distributed data
+store. It allows you to execute queries via a
+[JSON-based query language](http://druid.io/docs/0.9.0/querying/querying.html),
+in particular OLAP-style queries.
+Druid can be loaded in batch mode or continuously; one of Druid's key
+differentiators is its ability to
+[load from a streaming source such as Kafka](http://druid.io/docs/0.9.0/ingestion/stream-ingestion.html)
+and have the data available for query within milliseconds.
+
+Calcite's Druid adapter allows you to query the data using SQL,
+combining it with data in other Calcite schemas.
+
+First, we need a
+[model definition]({{ site.baseurl }}/docs/model.html).
+The model gives Calcite the necessary parameters to create an instance
+of the Druid adapter.
+
+A basic example of a model file is given below:
+
+{% highlight json %}
+{
+  "version": "1.0",
+  "defaultSchema": "wiki",
+  "schemas": [
+    {
+      "type": "custom",
+      "name": "wiki",
+      "factory": "org.apache.calcite.adapter.druid.DruidSchemaFactory",
+      "operand": {
+        "url": "http://localhost:8082/druid/v2/?pretty"
+      },
+      "tables": [
+        {
+          "name": "wiki",
+          "factory": "org.apache.calcite.adapter.druid.DruidTableFactory",
+          "operand": {
+            "dataSource": "wikiticker",
+            "interval": "1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z",
+            "timestampColumn": "time",
+            "dimensions": [
+              "channel",
+              "cityName",
+              "comment",
+              "countryIsoCode",
+              "countryName",
+              "isAnonymous",
+              "isMinor",
+              "isNew",
+              "isRobot",
+              "isUnpatrolled",
+              "metroCode",
+              "namespace",
+              "page",
+              "regionIsoCode",
+              "regionName",
+              "user"
+            ],
+            "metrics": [
+              {
+                "name" : "count",
+                "type" : "count"
+              },
+              {
+                "name" : "added",
+                "type" : "longSum",
+                "fieldName" : "added"
+              },
+              {
+                "name" : "deleted",
+                "type" : "longSum",
+                "fieldName" : "deleted"
+              },
+              {
+                "name" : "delta",
+                "type" : "longSum",
+                "fieldName" : "delta"
+              },
+              {
+                "name" : "user_unique",
+                "type" : "hyperUnique",
+                "fieldName" : "user"
+              }
+            ]
+          }
+        }
+      ]
+    }
+  ]
+}
+{% endhighlight %}
+
+This file is stored as `druid/src/test/resources/druid-wiki-model.json`,
+so you can connect to Druid via
+[`sqlline`](https://github.com/julianhyde/sqlline)
+as follows:
+
+{% highlight bash %}
+$ ./sqlline
+sqlline> !connect jdbc:calcite:model=druid/src/test/resources/druid-wiki-model.json admin admin
+sqlline> select "countryName", cast(count(*) as integer) as c
+         from "wiki"
+         group by "countryName"
+         order by c desc limit 5;
++----------------+------------+
+| countryName    |     C      |
++----------------+------------+
+|                | 35445      |
+| United States  | 528        |
+| Italy          | 256        |
+| United Kingdom | 234        |
+| France         | 205        |
++----------------+------------+
+5 rows selected (0.279 seconds)
+sqlline>
+{% endhighlight %}
+
+That query shows the top 5 countries of origin of wiki page edits
+on 2015-09-12 (the date covered by the wikiticker data set).
+
+Now let's see how the query was evaluated:
+
+{% highlight bash %}
+sqlline> !set outputformat csv
+sqlline> explain plan for
+         select "countryName", cast(count(*) as integer) as c
+         from "wiki"
+         group by "countryName"
+         order by c desc limit 5;
+'PLAN'
+'EnumerableInterpreter
+  BindableProject(countryName=[$0], C=[CAST($1):INTEGER NOT NULL])
+    BindableSort(sort0=[$1], dir0=[DESC], fetch=[5])
+      DruidQuery(table=[[wiki, wiki]], groups=[{4}], aggs=[[COUNT()]])
+'
+1 row selected (0.024 seconds)
+{% endhighlight %}
+
+That plan shows that Calcite was able to push down the `GROUP BY`
+part of the query to Druid, including the `COUNT(*)` function,
+but not the `ORDER BY ... LIMIT`. (We plan to lift this restriction;
+see [[CALCITE-1206](https://issues.apache.org/jira/browse/CALCITE-1206)].)
+
+# Foodmart data set
+
+The test VM also includes a data set that denormalizes
+the sales, product and customer tables of the Foodmart schema
+into a single Druid data set called "foodmart".
+
+You can access it via the
+`druid/src/test/resources/druid-foodmart-model.json` model.

http://git-wip-us.apache.org/repos/asf/calcite/blob/dd8d3c58/sqlline
----------------------------------------------------------------------
diff --git a/sqlline b/sqlline
index 4af3222..e1b13c7 100755
--- a/sqlline
+++ b/sqlline
@@ -37,7 +37,7 @@ if [ ! -f target/fullclasspath.txt ]; then
 fi
 
 CP=
-for module in core avatica cassandra mongodb spark splunk example/csv example/function; do
+for module in core avatica cassandra druid mongodb spark splunk example/csv example/function; do
   CP=${CP}${module}/target/classes:
   CP=${CP}${module}/target/test-classes:
 done