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 2018/03/04 21:15:30 UTC

[3/3] calcite git commit: [CALCITE-2088] Chinook database with simple end-to-end tests for Calcite JDBC (Piotr Bojko)

[CALCITE-2088] Chinook database with simple end-to-end tests for Calcite JDBC (Piotr Bojko)

Tests use the chinook-data-hsqldb data set from maven central.

Fix bug, introduced in [CALCITE-2128], where JdbcJoinRule is
erroneously applied to SemiJoin.

In gitignore, ignore netbeans project config overrides.

Close apache/calcite#600


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

Branch: refs/heads/master
Commit: 81d59679b3ffd90339df7d8463c9865b89867e98
Parents: cc983a6
Author: Piotr Bojko <pt...@gmail.com>
Authored: Wed Jan 3 14:44:00 2018 +0100
Committer: Julian Hyde <jh...@apache.org>
Committed: Sat Mar 3 21:35:17 2018 -0800

----------------------------------------------------------------------
 .gitignore                                      |  21 ++
 .../apache/calcite/adapter/jdbc/JdbcRules.java  |   6 +
 .../calcite/rel/convert/ConverterRule.java      |   3 +
 plus/pom.xml                                    |  45 +++-
 .../chinook/CalciteConnectionProvider.java      |  58 +++++
 .../calcite/chinook/ConnectionFactory.java      |  64 +++++
 .../calcite/chinook/EnvironmentFairy.java       |  55 +++++
 .../chinook/PreferredAlbumsTableFactory.java    |  75 ++++++
 .../chinook/PreferredGenresTableFactory.java    |  75 ++++++
 .../apache/calcite/chinook/package-info.java    |  26 ++
 plus/src/main/resources/chinook/chinook.json    |  42 ++++
 .../apache/calcite/chinook/EndToEndTest.java    |  65 +++++
 .../java/org/apache/calcite/test/PlusSuite.java |   4 +-
 plus/src/test/resources/sql/basic.iq            | 246 +++++++++++++++++++
 .../sql/preferred-for-specific-user.iq          |  93 +++++++
 pom.xml                                         |  14 +-
 16 files changed, 886 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 9c54233..583653d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,18 @@
+# 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.
+#
 *~
 target
 .idea
@@ -12,3 +27,9 @@ settings.xml
 .classpath
 .settings
 .checkstyle
+
+# netbeans
+nb-configuration.xml
+*/nb-configuration.xml
+
+# End .gitignore

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
index 44f9c09..8c07fef 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
@@ -44,6 +44,7 @@ import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Minus;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.core.SemiJoin;
 import org.apache.calcite.rel.core.Sort;
 import org.apache.calcite.rel.core.TableModify;
 import org.apache.calcite.rel.core.Union;
@@ -119,6 +120,11 @@ public class JdbcRules {
     }
 
     @Override public RelNode convert(RelNode rel) {
+      if (rel instanceof SemiJoin) {
+        // It's not possible to convert semi-joins. They have fewer columns
+        // than regular joins.
+        return null;
+      }
       return convert((Join) rel, true);
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java b/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
index ef8d629..149ea1e 100644
--- a/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/convert/ConverterRule.java
@@ -105,6 +105,9 @@ public abstract class ConverterRule extends RelOptRule {
     return inTrait.getTraitDef();
   }
 
+  /** Converts a relational expression to the target trait(s) of this rule.
+   *
+   * <p>Returns null if conversion is not possible. */
   public abstract RelNode convert(RelNode rel);
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/pom.xml
----------------------------------------------------------------------
diff --git a/plus/pom.xml b/plus/pom.xml
index a7f4332..8bcbb3a 100644
--- a/plus/pom.xml
+++ b/plus/pom.xml
@@ -58,8 +58,6 @@ limitations under the License.
     <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
-      <!-- Override parent POM. Airlift needs guava-15.0, but doesn't say. -->
-      <version>15.0</version>
     </dependency>
     <dependency>
       <groupId>io.airlift.tpch</groupId>
@@ -73,6 +71,15 @@ limitations under the License.
     </dependency>
     <dependency>
       <groupId>net.hydromatic</groupId>
+      <artifactId>chinook-data-hsqldb</artifactId>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>net.hydromatic</groupId>
+      <artifactId>quidem</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>net.hydromatic</groupId>
       <artifactId>tpcds</artifactId>
       <type>jar</type>
     </dependency>
@@ -81,14 +88,46 @@ limitations under the License.
       <artifactId>hamcrest-core</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.incava</groupId>
+      <artifactId>java-diff</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
-
   <build>
     <plugins>
       <!-- Sorted by groupId, artifactId. Put versions in
            pluginManagement in the root POM, not here. -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>${maven-dependency-plugin.version}</version>
+        <!-- configurations do not cascade, so all of the definition from
+             ../pom.xml:build:plugin-management:plugins:plugin must be repeated in child poms -->
+        <executions>
+          <execution>
+            <id>analyze</id>
+            <goals>
+              <goal>analyze-only</goal>
+            </goals>
+            <configuration>
+              <failOnWarning>true</failOnWarning>
+              <!-- ignore "unused but declared" warnings -->
+              <ignoredUnusedDeclaredDependencies>
+                <ignoredUnusedDeclaredDependency>net.hydromatic:chinook-data-hsqldb</ignoredUnusedDeclaredDependency>
+                <ignoredUnusedDeclaredDependency>org.hsqldb:hsqldb</ignoredUnusedDeclaredDependency>
+                <ignoredUnusedDeclaredDependency>org.incava:java-diff</ignoredUnusedDeclaredDependency>
+              </ignoredUnusedDeclaredDependencies>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <executions>
           <execution>

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/CalciteConnectionProvider.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/CalciteConnectionProvider.java b/plus/src/main/java/org/apache/calcite/chinook/CalciteConnectionProvider.java
new file mode 100644
index 0000000..5dfd2bd
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/CalciteConnectionProvider.java
@@ -0,0 +1,58 @@
+/*
+ * 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.chinook;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.CharStreams;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import java.util.Properties;
+
+/**
+ * Provider of calcite connections for end-to-end tests.
+ */
+public class CalciteConnectionProvider {
+
+  private static final String DRIVER_URL = "jdbc:calcite:";
+
+  public Connection connection() throws IOException, SQLException {
+    return DriverManager.getConnection(DRIVER_URL, provideConnectionInfo());
+  }
+
+  private Properties provideConnectionInfo() throws IOException {
+    Properties info = new Properties();
+    info.setProperty("lex", "MYSQL");
+    info.setProperty("model", "inline:" + provideSchema());
+    return info;
+  }
+
+  private String provideSchema() throws IOException {
+    final InputStream stream =
+        getClass().getResourceAsStream("/chinook/chinook.json");
+    return CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8));
+  }
+
+}
+
+// End CalciteConnectionProvider.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/ConnectionFactory.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/ConnectionFactory.java b/plus/src/main/java/org/apache/calcite/chinook/ConnectionFactory.java
new file mode 100644
index 0000000..376a793
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/ConnectionFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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.chinook;
+
+import net.hydromatic.chinook.data.hsqldb.ChinookHsqldb;
+import net.hydromatic.quidem.Quidem;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+/**
+ * Wrapping connection factory for quidem
+ */
+public class ConnectionFactory implements Quidem.ConnectionFactory {
+
+  private static final CalciteConnectionProvider CALCITE = new CalciteConnectionProvider();
+
+  public Connection connect(String db, boolean bln) throws Exception {
+    return DBWrapper.valueOf(db).connection();
+  }
+
+  /**
+   * Wrapping with Fairy environmental decoration
+   */
+  private enum DBWrapper {
+    CALCITE_AS_ADMIN {
+      @Override public Connection connection() throws Exception {
+        EnvironmentFairy.login(EnvironmentFairy.User.ADMIN);
+        return CALCITE.connection();
+      }
+    },
+    CALCITE_AS_SPECIFIC_USER {
+      @Override public Connection connection() throws Exception {
+        EnvironmentFairy.login(EnvironmentFairy.User.SPECIFIC_USER);
+        return CALCITE.connection();
+      }
+    },
+    RAW {
+      @Override public Connection connection() throws Exception {
+        return DriverManager.getConnection(ChinookHsqldb.URI,
+            ChinookHsqldb.USER, ChinookHsqldb.PASSWORD);
+      }
+    };
+
+    public abstract Connection connection() throws Exception;
+  }
+
+}
+
+// End ConnectionFactory.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/EnvironmentFairy.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/EnvironmentFairy.java b/plus/src/main/java/org/apache/calcite/chinook/EnvironmentFairy.java
new file mode 100644
index 0000000..34c005f
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/EnvironmentFairy.java
@@ -0,0 +1,55 @@
+/*
+ * 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.chinook;
+
+/**
+ * Fairy simulates environment around Calcite.
+ *
+ * <p>An example property is the user on whose behalf Calcite is running the
+ * current query. Other properties can change from one query to another.
+ * Properties are held in thread-locals, so it is safe to set a property then
+ * read it from the same thread.
+ */
+public class EnvironmentFairy {
+
+  private static final ThreadLocal<User> USER = new ThreadLocal<User>() {
+    @Override protected User initialValue() {
+      return User.ADMIN;
+    }
+  };
+
+  private EnvironmentFairy() {
+  }
+
+  public static User getUser() {
+    return USER.get();
+  }
+
+  public static void login(User user) {
+    USER.set(user);
+  }
+
+  /**
+   * Who is emulated to being logged in?
+   */
+  public enum User {
+    ADMIN, SPECIFIC_USER
+  }
+
+}
+
+// End EnvironmentFairy.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/PreferredAlbumsTableFactory.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/PreferredAlbumsTableFactory.java b/plus/src/main/java/org/apache/calcite/chinook/PreferredAlbumsTableFactory.java
new file mode 100644
index 0000000..7349610
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/PreferredAlbumsTableFactory.java
@@ -0,0 +1,75 @@
+/*
+ * 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.chinook;
+
+import org.apache.calcite.adapter.java.AbstractQueryableTable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.TableFactory;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+import com.google.common.collect.ContiguousSet;
+import com.google.common.collect.DiscreteDomain;
+import com.google.common.collect.Range;
+
+import java.util.Map;
+
+/**
+ * Factory for the table of albums preferred by the current user.
+ */
+public class PreferredAlbumsTableFactory implements TableFactory<AbstractQueryableTable> {
+  private static final Integer[] SPECIFIC_USER_PREFERRED_ALBUMS =
+      {4, 56, 154, 220, 321};
+  private static final int FIRST_ID = 1;
+  private static final int LAST_ID = 347;
+
+  @Override public AbstractQueryableTable create(
+      SchemaPlus schema,
+      String name,
+      Map<String, Object> operand,
+      RelDataType rowType) {
+    return new AbstractQueryableTable(Integer.class) {
+      @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+        return typeFactory.builder().add("ID", SqlTypeName.INTEGER).build();
+      }
+
+      @Override public Queryable<Integer> asQueryable(
+          QueryProvider qp,
+          SchemaPlus sp,
+          String string) {
+        return fetchPreferredAlbums();
+      }
+    };
+  }
+
+  private Queryable<Integer> fetchPreferredAlbums() {
+    if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) {
+      return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_ALBUMS).asQueryable();
+    } else {
+      final ContiguousSet<Integer> set =
+          ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID),
+              DiscreteDomain.integers());
+      return Linq4j.asEnumerable(set).asQueryable();
+    }
+  }
+}
+
+// End PreferredAlbumsTableFactory.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/PreferredGenresTableFactory.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/PreferredGenresTableFactory.java b/plus/src/main/java/org/apache/calcite/chinook/PreferredGenresTableFactory.java
new file mode 100644
index 0000000..28e043e
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/PreferredGenresTableFactory.java
@@ -0,0 +1,75 @@
+/*
+ * 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.chinook;
+
+import org.apache.calcite.adapter.java.AbstractQueryableTable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.TableFactory;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+import com.google.common.collect.ContiguousSet;
+import com.google.common.collect.DiscreteDomain;
+import com.google.common.collect.Range;
+
+import java.util.Map;
+
+/**
+ * Factory for the table of genres preferred by the current user.
+ */
+public class PreferredGenresTableFactory implements TableFactory<AbstractQueryableTable> {
+  private static final Integer[] SPECIFIC_USER_PREFERRED_GENRES =
+      {1, 2, 7, 9, 15};
+  private static final int FIRST_ID = 1;
+  private static final int LAST_ID = 25;
+
+  @Override public AbstractQueryableTable create(
+      SchemaPlus schema,
+      String name,
+      Map<String, Object> operand,
+      RelDataType rowType) {
+    return new AbstractQueryableTable(Integer.class) {
+      @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+        return typeFactory.builder().add("ID", SqlTypeName.INTEGER).build();
+      }
+
+      @Override public Queryable<Integer> asQueryable(
+          QueryProvider qp,
+          SchemaPlus sp,
+          String string) {
+        return fetchPreferredGenres();
+      }
+    };
+  }
+
+  private Queryable<Integer> fetchPreferredGenres() {
+    if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) {
+      return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_GENRES).asQueryable();
+    } else {
+      final ContiguousSet<Integer> set =
+          ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID),
+              DiscreteDomain.integers());
+      return Linq4j.asEnumerable(set).asQueryable();
+    }
+  }
+}
+
+// End PreferredGenresTableFactory.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/java/org/apache/calcite/chinook/package-info.java
----------------------------------------------------------------------
diff --git a/plus/src/main/java/org/apache/calcite/chinook/package-info.java b/plus/src/main/java/org/apache/calcite/chinook/package-info.java
new file mode 100644
index 0000000..cd46445
--- /dev/null
+++ b/plus/src/main/java/org/apache/calcite/chinook/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+/**
+ * End to end tests.
+ */
+@PackageMarker
+package org.apache.calcite.chinook;
+
+import org.apache.calcite.avatica.util.PackageMarker;
+
+// End package-info.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/main/resources/chinook/chinook.json
----------------------------------------------------------------------
diff --git a/plus/src/main/resources/chinook/chinook.json b/plus/src/main/resources/chinook/chinook.json
new file mode 100644
index 0000000..b687c4c
--- /dev/null
+++ b/plus/src/main/resources/chinook/chinook.json
@@ -0,0 +1,42 @@
+{
+  "version": "1.0",
+  "defaultSchema": "ENHANCED",
+  "schemas": [
+    {
+      "name": "CHINOOK",
+      "type": "jdbc",
+      "jdbcDriver": "org.hsqldb.jdbc.JDBCDriver",
+      "jdbcUrl": "jdbc:hsqldb:res:chinook",
+      "jdbcUser": "sa",
+      "jdbcPassword": ""
+    },
+    {
+      "name": "ENHANCED",
+      "type": "custom",
+      "factory": "org.apache.calcite.schema.impl.AbstractSchema$Factory",
+      "operand": {},
+      "tables": [
+        {
+          "name" : "PREFERRED_TRACKS",
+          "type" : "view",
+          "sql" : [
+            "SELECT trackid, name, albumid, mediatypeid, genreid, composer, milliseconds, bytes, unitprice ",
+            "FROM chinook.track AS tr",
+            "WHERE tr.genreid IN (SELECT id FROM preferred_genres) ",
+            "OR tr.albumid IN (SELECT id FROM preferred_albums)"
+          ]
+        },
+        {
+          "name": "PREFERRED_GENRES",
+          "type": "table",
+          "factory": "org.apache.calcite.chinook.PreferredGenresTableFactory"
+        },
+        {
+          "name": "PREFERRED_ALBUMS",
+          "type": "table",
+          "factory": "org.apache.calcite.chinook.PreferredAlbumsTableFactory"
+        }
+      ]
+    }
+  ]
+}

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/test/java/org/apache/calcite/chinook/EndToEndTest.java
----------------------------------------------------------------------
diff --git a/plus/src/test/java/org/apache/calcite/chinook/EndToEndTest.java b/plus/src/test/java/org/apache/calcite/chinook/EndToEndTest.java
new file mode 100644
index 0000000..5e72ec3
--- /dev/null
+++ b/plus/src/test/java/org/apache/calcite/chinook/EndToEndTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.chinook;
+
+import org.apache.calcite.test.QuidemTest;
+
+import net.hydromatic.quidem.Quidem;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Collection;
+
+/**
+ * Entry point for all end-to-end tests based on Chinook data in HSQLDB wrapped
+ * by Calcite schema.
+ */
+@RunWith(Parameterized.class)
+public class EndToEndTest extends QuidemTest {
+  public EndToEndTest(String path) {
+    super(path);
+  }
+
+  /** Runs a test from the command line.
+   *
+   * <p>For example:
+   *
+   * <blockquote>
+   *   <code>java EndToEndTest sql/basic.iq</code>
+   * </blockquote> */
+  public static void main(String[] args) throws Exception {
+    for (String arg : args) {
+      new EndToEndTest(arg).test();
+    }
+  }
+
+  /** For {@link Parameterized} runner. */
+  @Parameterized.Parameters(name = "{index}: quidem({0})")
+  public static Collection<Object[]> data() {
+    // Start with a test file we know exists, then find the directory and list
+    // its files.
+    final String first = "sql/basic.iq";
+    return data(first);
+  }
+
+  @Override protected Quidem.ConnectionFactory createConnectionFactory() {
+    return new ConnectionFactory();
+  }
+}
+
+// End EndToEndTest.java

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/test/java/org/apache/calcite/test/PlusSuite.java
----------------------------------------------------------------------
diff --git a/plus/src/test/java/org/apache/calcite/test/PlusSuite.java b/plus/src/test/java/org/apache/calcite/test/PlusSuite.java
index 3a2d0e4..5f8a67a 100644
--- a/plus/src/test/java/org/apache/calcite/test/PlusSuite.java
+++ b/plus/src/test/java/org/apache/calcite/test/PlusSuite.java
@@ -19,6 +19,7 @@ package org.apache.calcite.test;
 import org.apache.calcite.adapter.os.OsAdapterTest;
 import org.apache.calcite.adapter.tpcds.TpcdsTest;
 import org.apache.calcite.adapter.tpch.TpchTest;
+import org.apache.calcite.chinook.EndToEndTest;
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
@@ -30,7 +31,8 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses({
     OsAdapterTest.class,
     TpcdsTest.class,
-    TpchTest.class
+    TpchTest.class,
+    EndToEndTest.class
     })
 public class PlusSuite {
 }

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/test/resources/sql/basic.iq
----------------------------------------------------------------------
diff --git a/plus/src/test/resources/sql/basic.iq b/plus/src/test/resources/sql/basic.iq
new file mode 100644
index 0000000..b936b07
--- /dev/null
+++ b/plus/src/test/resources/sql/basic.iq
@@ -0,0 +1,246 @@
+# 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.
+#
+!use CALCITE_AS_ADMIN
+!set outputformat mysql
+
+# count returns number of rows in table
+SELECT COUNT(*) as C1 FROM chinook.album;
++-----+
+| C1  |
++-----+
+| 347 |
++-----+
+(1 row)
+
+!ok
+
+SELECT ar.name as NAME, COUNT(tr.trackid) AS TRACKS_COUNT, SUM(tr.milliseconds) AS MS_TOTAL
+FROM chinook.artist AS ar
+JOIN chinook.album AS al ON ar.artistid = al.artistid
+JOIN chinook.track as tr ON al.albumid = tr.albumid
+GROUP BY ar.name;
+
++---------------------------------------------------------------------------------------+--------------+-----------+
+| NAME                                                                                  | TRACKS_COUNT | MS_TOTAL  |
++---------------------------------------------------------------------------------------+--------------+-----------+
+| AC/DC                                                                                 |           18 |   4853674 |
+| Aaron Copland & London Symphony Orchestra                                             |            1 |    198064 |
+| Aaron Goldberg                                                                        |            1 |    266936 |
+| Academy of St. Martin in the Fields & Sir Neville Marriner                            |            2 |    465201 |
+| Academy of St. Martin in the Fields Chamber Ensemble & Sir Neville Marriner           |            1 |    348971 |
+| Academy of St. Martin in the Fields, John Birch, Sir Neville Marriner & Sylvia McNair |            1 |    258924 |
+| Academy of St. Martin in the Fields, Sir Neville Marriner & Thurston Dart             |            1 |    225933 |
+| Accept                                                                                |            4 |   1200650 |
+| Adrian Leaper & Doreen de Feis                                                        |            1 |    567494 |
+| Aerosmith                                                                             |           15 |   4411709 |
+| Aisha Duo                                                                             |            2 |    553888 |
+| Alanis Morissette                                                                     |           13 |   3450925 |
+| Alberto Turco & Nova Schola Gregoriana                                                |            1 |    245317 |
+| Alice In Chains                                                                       |           12 |   3249365 |
+| Amy Winehouse                                                                         |           23 |   5579857 |
+| Anne-Sophie Mutter, Herbert Von Karajan & Wiener Philharmoniker                       |            1 |    199086 |
+| Antal Doráti & London Symphony Orchestra                                              |            1 |    412000 |
+| Antônio Carlos Jobim                                                                  |           31 |   7128385 |
+| Apocalyptica                                                                          |            8 |   2671407 |
+| Aquaman                                                                               |            1 |   2484567 |
+| Audioslave                                                                            |           40 |  10655588 |
+| BackBeat                                                                              |           12 |   1615722 |
+| Barry Wordsworth & BBC Concert Orchestra                                              |            1 |    250031 |
+| Battlestar Galactica                                                                  |           20 |  55409291 |
+| Battlestar Galactica (Classic)                                                        |           24 |  70213784 |
+| Berliner Philharmoniker & Hans Rosbaud                                                |            1 |    406000 |
+| Berliner Philharmoniker & Herbert Von Karajan                                         |            3 |    851101 |
+| Berliner Philharmoniker, Claudio Abbado & Sabine Meyer                                |            1 |    394482 |
+| Billy Cobham                                                                          |            8 |   2680524 |
+| Black Label Society                                                                   |           18 |   5507674 |
+| Black Sabbath                                                                         |           17 |   4896722 |
+| Body Count                                                                            |           17 |   3192389 |
+| Boston Symphony Orchestra & Seiji Ozawa                                               |            1 |    156710 |
+| Britten Sinfonia, Ivor Bolton & Lesley Garrett                                        |            1 |    338243 |
+| Bruce Dickinson                                                                       |           11 |   3694022 |
+| Buddy Guy                                                                             |           11 |   2636849 |
+| C. Monteverdi, Nigel Rogers - Chiaroscuro; London Baroque; London Cornett & Sackbu    |            1 |     66639 |
+| Caetano Veloso                                                                        |           21 |   4779093 |
+| Cake                                                                                  |            1 |    234013 |
+| Calexico                                                                              |            1 |    215386 |
+| Charles Dutoit & L'Orchestre Symphonique de Montréal                                  |            1 |    385506 |
+| Chicago Symphony Chorus, Chicago Symphony Orchestra & Sir Georg Solti                 |            1 |    274504 |
+| Chicago Symphony Orchestra & Fritz Reiner                                             |            1 |    545203 |
+| Chico Buarque                                                                         |           34 |   7875643 |
+| Chico Science & Nação Zumbi                                                           |           36 |   7255443 |
+| Choir Of Westminster Abbey & Simon Preston                                            |            1 |    240666 |
+| Chor der Wiener Staatsoper, Herbert Von Karajan & Wiener Philharmoniker               |            1 |    132932 |
+| Chris Cornell                                                                         |           14 |   3292399 |
+| Christopher O'Riley                                                                   |            1 |    101293 |
+| Cidade Negra                                                                          |           31 |   7376311 |
+| Cláudio Zoli                                                                          |           10 |   2559734 |
+| Creedence Clearwater Revival                                                          |           40 |   8586509 |
+| Cássia Eller                                                                          |           30 |   6879099 |
+| David Coverdale                                                                       |           12 |   3618267 |
+| Deep Purple                                                                           |           92 |  32259613 |
+| Def Leppard                                                                           |           16 |   4401077 |
+| Dennis Chambers                                                                       |            9 |   3440820 |
+| Djavan                                                                                |           26 |   7284962 |
+| Dread Zeppelin                                                                        |            1 |    310774 |
+| Ed Motta                                                                              |           14 |   3409704 |
+| Edo de Waart & San Francisco Symphony                                                 |            1 |    254930 |
+| Elis Regina                                                                           |           14 |   3095920 |
+| Emanuel Ax, Eugene Ormandy & Philadelphia Orchestra                                   |            1 |    560342 |
+| Emerson String Quartet                                                                |            1 |    139200 |
+| English Concert & Trevor Pinnock                                                      |            2 |    391788 |
+| Equale Brass Ensemble, John Eliot Gardiner & Munich Monteverdi Orchestra and Choir    |            1 |    142081 |
+| Eric Clapton                                                                          |           48 |  12486478 |
+| Eugene Ormandy                                                                        |            3 |   1335536 |
+| Faith No More                                                                         |           52 |  13211898 |
+| Falamansa                                                                             |           14 |   2842456 |
+| Felix Schmidt, London Symphony Orchestra & Rafael Frühbeck de Burgos                  |            1 |    483133 |
+| Foo Fighters                                                                          |           44 |  11124565 |
+| Frank Sinatra                                                                         |           24 |   4539941 |
+| Frank Zappa & Captain Beefheart                                                       |            9 |   2465929 |
+| Fretwork                                                                              |            1 |    253281 |
+| Funk Como Le Gusta                                                                    |           16 |   4165844 |
+| Gene Krupa                                                                            |           22 |   4637011 |
+| Gerald Moore                                                                          |            1 |    261849 |
+| Gilberto Gil                                                                          |           32 |   7719246 |
+| Godsmack                                                                              |           12 |   2846138 |
+| Gonzaguinha                                                                           |           14 |   2935452 |
+| Green Day                                                                             |           34 |   7083399 |
+| Guns N' Roses                                                                         |           42 |  12355529 |
+| Gustav Mahler                                                                         |            1 |    223583 |
+| Göteborgs Symfoniker & Neeme Järvi                                                    |            1 |    286998 |
+| Habib Koité and Bamada                                                                |            2 |    586442 |
+| Herbert Von Karajan, Mirella Freni & Wiener Philharmoniker                            |            1 |    277639 |
+| Heroes                                                                                |           23 |  59780268 |
+| Hilary Hahn, Jeffrey Kahane, Los Angeles Chamber Orchestra & Margaret Batjer          |            1 |    193722 |
+| House Of Pain                                                                         |           19 |   3269060 |
+| Incognito                                                                             |           13 |   4421323 |
+| Iron Maiden                                                                           |          213 |  71844745 |
+| Itzhak Perlman                                                                        |            1 |    265541 |
+| JET                                                                                   |           13 |   2919830 |
+| James Brown                                                                           |           20 |   4211242 |
+| James Levine                                                                          |            1 |    243436 |
+| Jamiroquai                                                                            |           32 |  10475399 |
+| Jimi Hendrix                                                                          |           17 |   3618056 |
+| Joe Satriani                                                                          |           10 |   2259724 |
+| Jorge Ben                                                                             |           14 |   4571265 |
+| Jota Quest                                                                            |           12 |   3016355 |
+| João Suplicy                                                                          |           14 |   3065723 |
+| Judas Priest                                                                          |           16 |   3973111 |
+| Julian Bream                                                                          |            1 |    285673 |
+| Karsh Kale                                                                            |            2 |    693207 |
+| Kent Nagano and Orchestre de l'Opéra de Lyon                                          |            1 |    376510 |
+| Kiss                                                                                  |           35 |   7980393 |
+| Led Zeppelin                                                                          |          114 |  40121414 |
+| Legião Urbana                                                                         |           31 |   8166856 |
+| Lenny Kravitz                                                                         |           57 |  15065731 |
+| Leonard Bernstein & New York Philharmonic                                             |            1 |    596519 |
+| Les Arts Florissants & William Christie                                               |            1 |    110266 |
+| London Symphony Orchestra & Sir Charles Mackerras                                     |            1 |    304226 |
+| Lost                                                                                  |           92 | 238278582 |
+| Luciana Souza/Romero Lubambo                                                          |            1 |    172710 |
+| Luciano Pavarotti                                                                     |            1 |    176911 |
+| Lulu Santos                                                                           |           28 |   6468346 |
+| Marcos Valle                                                                          |           17 |   3701306 |
+| Marillion                                                                             |           10 |   2477370 |
+| Marisa Monte                                                                          |           18 |   3433813 |
+| Martin Roscoe                                                                         |            1 |    333669 |
+| Marvin Gaye                                                                           |           18 |   3488122 |
+| Maurizio Pollini                                                                      |            1 |    391000 |
+| Mela Tenenbaum, Pro Musica Prague & Richard Kapp                                      |            1 |    493573 |
+| Men At Work                                                                           |           10 |   2602784 |
+| Metallica                                                                             |          112 |  38916130 |
+| Michael Tilson Thomas & San Francisco Symphony                                        |            2 |    836982 |
+| Michele Campanella                                                                    |            1 |     51780 |
+| Miles Davis                                                                           |           37 |  12130621 |
+| Milton Nascimento                                                                     |           26 |   5918107 |
+| Motörhead                                                                             |           15 |   2735483 |
+| Mônica Marianno                                                                       |           12 |   2645702 |
+| Mötley Crüe                                                                           |           17 |   4435165 |
+| Nash Ensemble                                                                         |            1 |    221331 |
+| Nicolaus Esterhazy Sinfonia                                                           |            1 |    356426 |
+| Nirvana                                                                               |           29 |   5800447 |
+| O Rappa                                                                               |           17 |   4428843 |
+| O Terço                                                                               |           15 |   3594651 |
+| Olodum                                                                                |           14 |   3019828 |
+| Orchestra of The Age of Enlightenment                                                 |            1 |    307244 |
+| Orchestre Révolutionnaire et Romantique & John Eliot Gardiner                         |            1 |    392462 |
+| Os Mutantes                                                                           |           14 |   3351947 |
+| Os Paralamas Do Sucesso                                                               |           49 |  10647198 |
+| Otto Klemperer & Philharmonia Orchestra                                               |            1 |    339567 |
+| Ozzy Osbourne                                                                         |           32 |  10441129 |
+| Page & Plant                                                                          |           12 |   3649040 |
+| Passengers                                                                            |           14 |   3489692 |
+| Paul D'Ianno                                                                          |           10 |   2547615 |
+| Pearl Jam                                                                             |           67 |  16502824 |
+| Philharmonia Orchestra & Sir Neville Marriner                                         |            1 |    387826 |
+| Philip Glass Ensemble                                                                 |            1 |    206005 |
+| Pink Floyd                                                                            |            9 |   2572638 |
+| Planet Hemp                                                                           |           16 |   2967110 |
+| Queen                                                                                 |           45 |  10428501 |
+| R.E.M.                                                                                |           41 |   9965537 |
+| R.E.M. Feat. Kate Pearson                                                             |           11 |   2650117 |
+| Raimundos                                                                             |           10 |   1738470 |
+| Raul Seixas                                                                           |           14 |   2833311 |
+| Red Hot Chili Peppers                                                                 |           48 |  11952485 |
+| Richard Marlow & The Choir of Trinity College, Cambridge                              |            1 |    501503 |
+| Roger Norrington, London Classical Players                                            |            1 |    364296 |
+| Royal Philharmonic Orchestra & Sir Thomas Beecham                                     |            1 |    306687 |
+| Rush                                                                                  |           14 |   4548694 |
+| Santana                                                                               |           27 |  12847973 |
+| Scholars Baroque Ensemble                                                             |            1 |    582029 |
+| Scorpions                                                                             |           12 |   3448442 |
+| Sergei Prokofiev & Yuri Temirkanov                                                    |            1 |    254001 |
+| Sir Georg Solti & Wiener Philharmoniker                                               |            1 |    189008 |
+| Sir Georg Solti, Sumi Jo & Wiener Philharmoniker                                      |            1 |    174813 |
+| Skank                                                                                 |           23 |   5887990 |
+| Smashing Pumpkins                                                                     |           34 |   8662239 |
+| Soundgarden                                                                           |           17 |   4752029 |
+| Spyro Gyra                                                                            |           21 |   5974246 |
+| Stevie Ray Vaughan & Double Trouble                                                   |           10 |   2468671 |
+| Stone Temple Pilots                                                                   |           12 |   3218749 |
+| System Of A Down                                                                      |           11 |   2172650 |
+| Temple of the Dog                                                                     |           10 |   3316905 |
+| Terry Bozzio, Tony Levin & Steve Stevens                                              |            7 |   4030534 |
+| The 12 Cellists of The Berlin Philharmonic                                            |            1 |    289388 |
+| The Black Crowes                                                                      |           19 |   6266088 |
+| The Clash                                                                             |           18 |   3864679 |
+| The Cult                                                                              |           30 |   7715643 |
+| The Doors                                                                             |           11 |   2669734 |
+| The King's Singers                                                                    |            2 |    202962 |
+| The Office                                                                            |           53 |  74928465 |
+| The Police                                                                            |           14 |   3578900 |
+| The Posies                                                                            |            2 |    411967 |
+| The Rolling Stones                                                                    |           41 |  10114436 |
+| The Tea Party                                                                         |           26 |   7006577 |
+| The Who                                                                               |           20 |   4580064 |
+| Tim Maia                                                                              |           30 |   5515219 |
+| Titãs                                                                                 |           38 |   7732518 |
+| Ton Koopman                                                                           |            1 |    153901 |
+| Toquinho & Vinícius                                                                   |           15 |   3293850 |
+| U2                                                                                    |          135 |  35421983 |
+| UB40                                                                                  |           14 |   3523466 |
+| Van Halen                                                                             |           52 |  12297219 |
+| Various Artists                                                                       |           56 |  13995811 |
+| Velvet Revolver                                                                       |           13 |   3417071 |
+| Vinícius De Moraes                                                                    |           15 |   3254721 |
+| Wilhelm Kempff                                                                        |            1 |    120463 |
+| Yehudi Menuhin                                                                        |            1 |    299350 |
+| Yo-Yo Ma                                                                              |            1 |    143288 |
+| Zeca Pagodinho                                                                        |           19 |   4065140 |
++---------------------------------------------------------------------------------------+--------------+-----------+
+(204 rows)
+
+!ok

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/plus/src/test/resources/sql/preferred-for-specific-user.iq
----------------------------------------------------------------------
diff --git a/plus/src/test/resources/sql/preferred-for-specific-user.iq b/plus/src/test/resources/sql/preferred-for-specific-user.iq
new file mode 100644
index 0000000..9822881
--- /dev/null
+++ b/plus/src/test/resources/sql/preferred-for-specific-user.iq
@@ -0,0 +1,93 @@
+# 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.
+!use CALCITE_AS_SPECIFIC_USER
+!set outputformat mysql
+
+# Preferred genres
+SELECT * FROM preferred_genres;
++----+
+| ID |
++----+
+|  1 |
+| 15 |
+|  2 |
+|  7 |
+|  9 |
++----+
+(5 rows)
+
+!ok
+
+# Preferred albums
+SELECT * FROM preferred_albums;
++-----+
+| ID  |
++-----+
+| 154 |
+| 220 |
+| 321 |
+|   4 |
+|  56 |
++-----+
+(5 rows)
+
+!ok
+
+# Preferred tracks count by genres
+SELECT tr.genreid, COUNT(tr.trackid) as TRACKS_COUNT
+FROM chinook.track AS tr
+JOIN preferred_genres AS pg ON tr.genreid = pg.id
+GROUP BY tr.genreid;
++---------+--------------+
+| genreid | TRACKS_COUNT |
++---------+--------------+
+|       1 |         1297 |
+|      15 |           30 |
+|       2 |          130 |
+|       7 |          579 |
+|       9 |           48 |
++---------+--------------+
+(5 rows)
+
+!ok
+
+# should be just like above Preferred tracks count by genres
+SELECT tr.genreid, COUNT(tr.trackid) as TRACKS_COUNT
+FROM chinook.track AS tr
+WHERE tr.genreid IN (SELECT pg.id FROM preferred_genres AS pg)
+GROUP BY tr.genreid;
++---------+--------------+
+| genreid | TRACKS_COUNT |
++---------+--------------+
+|       1 |         1297 |
+|      15 |           30 |
+|       2 |          130 |
+|       7 |          579 |
+|       9 |           48 |
++---------+--------------+
+(5 rows)
+
+!ok
+
+# Preferred genres
+SELECT COUNT(*) AS TRACKS_COUNT FROM preferred_tracks;
++--------------+
+| TRACKS_COUNT |
++--------------+
+|         2115 |
++--------------+
+(1 row)
+
+!ok

http://git-wip-us.apache.org/repos/asf/calcite/blob/81d59679/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 85b7187..7b65343 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@ limitations under the License.
     <build-helper-maven-plugin.version>1.9</build-helper-maven-plugin.version>
     <cassandra-driver-core.version>3.4.0</cassandra-driver-core.version>
     <checksum-maven-plugin.version>1.2</checksum-maven-plugin.version>
+    <chinook-data-hsqldb.version>0.1</chinook-data-hsqldb.version>
     <commons-dbcp.version>1.4</commons-dbcp.version>
     <commons-lang3.version>3.2</commons-lang3.version>
     <commons-logging.version>1.1.3</commons-logging.version>
@@ -78,8 +79,7 @@ limitations under the License.
     <geode.version>1.3.0</geode.version>
 
     <!-- We support (and test against) Guava versions between
-         14.0.1 (Hive) and 23.0. Default is 19.0 due to Cassandra adapter.
-         Some versions of Guava do not support JDK 7. -->
+         19.0 and 23.0. Default is 19.0 due to Cassandra adapter. -->
     <guava.version>19.0</guava.version>
     <joda.version>2.8.1</joda.version>
     <h2.version>1.4.185</h2.version>
@@ -308,6 +308,11 @@ limitations under the License.
       </dependency>
       <dependency>
         <groupId>net.hydromatic</groupId>
+        <artifactId>chinook-data-hsqldb</artifactId>
+        <version>${chinook-data-hsqldb.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>net.hydromatic</groupId>
         <artifactId>foodmart-data-hsqldb</artifactId>
         <version>${foodmart-data-hsqldb.version}</version>
       </dependency>
@@ -419,6 +424,11 @@ limitations under the License.
         <version>${hsqldb.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.hsqldb</groupId>
+        <artifactId>sqltool</artifactId>
+        <version>${hsqldb.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.incava</groupId>
         <artifactId>java-diff</artifactId>
         <version>${java-diff.version}</version>