You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by se...@apache.org on 2018/09/25 18:08:14 UTC
[1/2] calcite git commit: [CALCITE-2588] Run Geode Adapter tests with
an Embedded Instance
Repository: calcite
Updated Branches:
refs/heads/master 9ba9bdc1d -> ed424ed81
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java
new file mode 100644
index 0000000..b1045b3
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java
@@ -0,0 +1,154 @@
+/*
+ * 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.adapter.geode.rel;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.distributed.AbstractLauncher;
+import org.apache.geode.distributed.ServerLauncher;
+
+import com.google.common.base.Preconditions;
+
+import org.junit.rules.ExternalResource;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Manages embedded Geode instance using native {@link ServerLauncher}.
+ */
+public class GeodeEmbeddedPolicy extends ExternalResource {
+
+ private final ServerLauncher launcher;
+
+ private GeodeEmbeddedPolicy(final ServerLauncher launcher) {
+ Objects.requireNonNull(launcher, "launcher");
+ Preconditions.checkState(!launcher.isRunning(), "Launcher process is already running");
+ this.launcher = launcher;
+ }
+
+ @Override protected void before() {
+ requireStatus(AbstractLauncher.Status.NOT_RESPONDING);
+ launcher.start();
+ }
+
+ @Override protected void after() {
+ if (launcher.status().getStatus() == AbstractLauncher.Status.ONLINE) {
+ CacheFactory.getAnyInstance().close();
+ }
+
+ final Path pidFile = Paths.get(launcher.getWorkingDirectory()).resolve("vf.gf.server.pid");
+ launcher.stop();
+
+ if (Files.exists(pidFile)) {
+ // delete PID file. Otherwise ("next") geode instance complains about existing process
+ try {
+ Files.delete(pidFile);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+ }
+
+ /**
+ * Allows this instance to be shared by multiple test classes (in parallel). Guarantees that
+ * {@code before()} and {@code after()} methods will be called only once. This setup is useful
+ * for maven (surefire) plugin which executes tests in parallel (including {@code @ClassRule}
+ * methods) and may initialize (or destroy) same resource multiple times.
+ */
+ GeodeEmbeddedPolicy share() {
+ return new RefCountPolicy(this);
+ }
+
+ /**
+ * Returns current cache instance which was initialized for tests.
+ * @throws IllegalStateException if server process didn't start
+ */
+ Cache cache() {
+ requireStatus(AbstractLauncher.Status.ONLINE);
+ return CacheFactory.getAnyInstance();
+ }
+
+ private void requireStatus(AbstractLauncher.Status expected) {
+ final AbstractLauncher.Status current = launcher.status().getStatus();
+ Preconditions.checkState(current == expected,
+ "Expected state %s but got %s", expected, current);
+ }
+
+ static GeodeEmbeddedPolicy create() {
+ final ServerLauncher launcher = new ServerLauncher.Builder()
+ .setMemberName("fake-geode")
+ .set("log-file", "") // log to stdout
+ .set("log-level", "severe") // minimal logging
+ .set("bind-address", "127.0.0.1") // accept internal connections only
+ .setServerPort(0) // bind to any available port
+ .setPdxPersistent(false)
+ .setPdxReadSerialized(true)
+ .build();
+
+ return new GeodeEmbeddedPolicy(launcher);
+ }
+
+ /**
+ * Calls {@code before()} and {@code after()} methods only once (for first and last subscriber
+ * respectively). The implementation counts number of times {@link #before()} was called
+ * which determines number of "clients". Delegate {@link #after()} is called when that count
+ * reaches zero again (when last "client" called that method).
+ */
+ private static class RefCountPolicy extends GeodeEmbeddedPolicy {
+
+ private final AtomicInteger refCount;
+
+ private final GeodeEmbeddedPolicy policy;
+
+ RefCountPolicy(final GeodeEmbeddedPolicy policy) {
+ super(Objects.requireNonNull(policy, "policy").launcher);
+ this.policy = policy;
+ this.refCount = new AtomicInteger();
+ }
+
+ @Override GeodeEmbeddedPolicy share() {
+ // for cases like share().share()
+ return this;
+ }
+
+ @Override public synchronized void before() {
+ try {
+ if (refCount.get() == 0) {
+ // initialize only once
+ policy.before();
+ }
+ } finally {
+ refCount.incrementAndGet();
+ }
+ }
+
+ @Override protected void after() {
+ if (refCount.decrementAndGet() == 0) {
+ // destroy only once
+ policy.after();
+ }
+ }
+ }
+}
+
+// End GeodeEmbeddedPolicy.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsIT.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsIT.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsIT.java
deleted file mode 100644
index 2ca7df5..0000000
--- a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsIT.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.adapter.geode.rel;
-
-import org.apache.calcite.test.CalciteAssert;
-import org.apache.calcite.util.Sources;
-import org.apache.calcite.util.Util;
-
-import com.google.common.collect.ImmutableMap;
-
-import org.junit.Test;
-
-/**
- * Tests for the {@code org.apache.calcite.adapter.geode} package.
- *
- * <p>Before calling this rel, you need to populate Geode, as follows:
- *
- * <blockquote><code>
- * git clone https://github.com/vlsi/calcite-test-dataset<br>
- * cd calcite-rel-dataset<br>
- * mvn install
- * </code></blockquote>
- *
- * <p>This will create a virtual machine with Geode and the "bookshop" and "zips" rel dataset.
- */
-public class GeodeZipsIT {
- /**
- * Connection factory based on the "geode relational " model.
- */
- public static final ImmutableMap<String, String> GEODE_ZIPS =
- ImmutableMap.of("CONFORMANCE", "LENIENT", "model",
- Sources.of(GeodeZipsIT.class.getResource("/model-zips.json"))
- .file().getAbsolutePath());
-
-
- /**
- * Whether to run Geode tests. Enabled by default, however rel is only
- * included if "it" profile is activated ({@code -Pit}). To disable,
- * specify {@code -Dcalcite.rel.geode=false} on the Java command line.
- */
- public static final boolean ENABLED = Util.getBooleanProperty("calcite.rel.geode", true);
-
- /**
- * Whether to run this rel.
- */
- protected boolean enabled() {
- return ENABLED;
- }
-
-
- @Test
- public void testGroupByView() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"state\", SUM(\"pop\") FROM \"geode\".\"ZIPS\" GROUP BY \"state\"")
- .returnsCount(51)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{1}], EXPR$1=[SUM($0)])\n"
- + " GeodeProject(pop=[CAST($3):INTEGER], state=[CAST($4):VARCHAR(2) CHARACTER SET"
- + " \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testGroupByViewWithAliases() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"state\" as \"st\", SUM(\"pop\") \"po\" "
- + "FROM \"geode\".\"ZIPS\" GROUP BY "
- + "\"state\"")
- .returnsCount(51)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{1}], po=[SUM($0)])\n"
- + " GeodeProject(pop=[CAST($3):INTEGER], state=[CAST($4):VARCHAR(2) CHARACTER SET"
- + " \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testGroupByRaw() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"state\" as \"st\", SUM(\"pop\") \"po\" "
- + "FROM \"geode_raw\".\"Zips\" GROUP"
- + " BY \"state\"")
- .returnsCount(51)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{4}], po=[SUM($3)])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testGroupByRawWithAliases() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"state\" AS \"st\", SUM(\"pop\") AS \"po\" "
- + "FROM \"geode_raw\".\"Zips\" "
- + "GROUP BY \"state\"")
- .returnsCount(51)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{4}], po=[SUM($3)])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testMaxRaw() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT MAX(\"pop\") FROM \"geode_raw\".\"Zips\"")
- .returnsCount(1)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{}], EXPR$0=[MAX($3)])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testJoin() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"r\".\"_id\" FROM \"geode_raw\".\"Zips\" AS \"v\" JOIN \"geode_raw\""
- + ".\"Zips\" AS \"r\" ON \"v\".\"_id\" = \"r\".\"_id\" LIMIT 1")
- .returnsCount(1)
- .explainContains("PLAN=EnumerableCalc(expr#0..2=[{inputs}], _id1=[$t0])\n"
- + " EnumerableLimit(fetch=[1])\n"
- + " EnumerableJoin(condition=[=($1, $2)], joinType=[inner])\n"
- + " GeodeToEnumerableConverter\n"
- + " GeodeProject(_id=[$0], _id0=[CAST($0):VARCHAR CHARACTER SET "
- + "\"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n"
- + " GeodeToEnumerableConverter\n"
- + " GeodeProject(_id0=[CAST($0):VARCHAR CHARACTER SET \"ISO-8859-1\" COLLATE "
- + "\"ISO-8859-1$en_US$primary\"])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testSelectLocItem() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"loc\"[0] as \"lat\", \"loc\"[1] as \"lon\" "
- + "FROM \"geode_raw\".\"Zips\" LIMIT 1")
- .returnsCount(1)
- .returns("lat=-74.700748; lon=41.65158\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
- + " GeodeSort(fetch=[1])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-
- @Test
- public void testItemPredicate() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"loc\"[0] as \"lat\", \"loc\"[1] as \"lon\" "
- + "FROM \"geode_raw\".\"Zips\" WHERE \"loc\"[0] < 0 LIMIT 1")
- .returnsCount(1)
- .returns("lat=-74.700748; lon=41.65158\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
- + " GeodeSort(fetch=[1])\n"
- + " GeodeFilter(condition=[<(ITEM($2, 0), 0)])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
-
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE_ZIPS)
- .query("SELECT \"loc\"[0] as \"lat\", \"loc\"[1] as \"lon\" "
- + "FROM \"geode_raw\".\"Zips\" WHERE \"loc\"[0] > 0 LIMIT 1")
- .returnsCount(0)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
- + " GeodeSort(fetch=[1])\n"
- + " GeodeFilter(condition=[>(ITEM($2, 0), 0)])\n"
- + " GeodeTableScan(table=[[geode_raw, Zips]])\n");
- }
-}
-
-// End GeodeZipsIT.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsTest.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsTest.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsTest.java
new file mode 100644
index 0000000..7f23957
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeZipsTest.java
@@ -0,0 +1,191 @@
+/*
+ * 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.adapter.geode.rel;
+
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.ViewTable;
+import org.apache.calcite.schema.impl.ViewTableMacro;
+import org.apache.calcite.test.CalciteAssert;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * Tests based on {@code zips-min.json} dataset. Runs automatically as part of CI.
+ */
+public class GeodeZipsTest extends AbstractGeodeTest {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ Cache cache = POLICY.cache();
+ Region<?, ?> region = cache.<String, Object>createRegionFactory().create("zips");
+ new JsonLoader(region).loadClasspathResource("/zips-mini.json");
+ }
+
+ private CalciteAssert.ConnectionFactory newConnectionFactory() {
+ return new CalciteAssert.ConnectionFactory() {
+ @Override public Connection createConnection() throws SQLException {
+ final Connection connection = DriverManager.getConnection("jdbc:calcite:lex=JAVA");
+ final SchemaPlus root = connection.unwrap(CalciteConnection.class).getRootSchema();
+
+ root.add("geode", new GeodeSchema(POLICY.cache(), Collections.singleton("zips")));
+
+ // add calcite view programmatically
+ final String viewSql = "select \"_id\" AS \"id\", \"city\", \"loc\", "
+ + "cast(\"pop\" AS integer) AS \"pop\", cast(\"state\" AS varchar(2)) AS \"state\" "
+ + "from \"geode\".\"zips\"";
+
+
+ ViewTableMacro macro = ViewTable.viewMacro(root, viewSql,
+ Collections.singletonList("geode"), Arrays.asList("geode", "view"), false);
+ root.add("view", macro);
+
+ return connection;
+ }
+ };
+ }
+
+ private CalciteAssert.AssertThat calciteAssert() {
+ return CalciteAssert.that()
+ .with(newConnectionFactory());
+ }
+
+ @Test
+ public void testGroupByView() {
+ calciteAssert()
+ .query("SELECT state, SUM(pop) FROM view GROUP BY state")
+ .returnsCount(51)
+ .queryContains(
+ GeodeAssertions.query("SELECT state AS state, "
+ + "SUM(pop) AS EXPR$1 FROM /zips GROUP BY state"));
+ }
+
+ @Test
+ @Ignore("Currently fails")
+ public void testGroupByViewWithAliases() {
+ calciteAssert()
+ .query("SELECT state as st, SUM(pop) po "
+ + "FROM view GROUP BY state")
+ .queryContains(
+ GeodeAssertions.query("SELECT state, SUM(pop) AS po FROM /zips GROUP BY state"))
+ .returnsCount(51)
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{1}], po=[SUM($0)])\n"
+ + " GeodeProject(pop=[CAST($3):INTEGER], state=[CAST($4):VARCHAR(2) CHARACTER SET"
+ + " \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+
+ @Test
+ public void testGroupByRaw() {
+ calciteAssert()
+ .query("SELECT state as st, SUM(pop) po "
+ + "FROM geode.zips GROUP BY state")
+ .returnsCount(51)
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{4}], po=[SUM($3)])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+
+ @Test
+ public void testGroupByRawWithAliases() {
+ calciteAssert()
+ .query("SELECT state AS st, SUM(pop) AS po "
+ + "FROM geode.zips GROUP BY state")
+ .returnsCount(51)
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{4}], po=[SUM($3)])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+
+ @Test
+ public void testMaxRaw() {
+ calciteAssert()
+ .query("SELECT MAX(pop) FROM view")
+ .returns("EXPR$0=112047\n")
+ .queryContains(GeodeAssertions.query("SELECT MAX(pop) AS EXPR$0 FROM /zips"));
+ }
+
+ @Test
+ @Ignore("Currently fails")
+ public void testJoin() {
+ calciteAssert()
+ .query("SELECT r._id FROM geode.zips AS v "
+ + "JOIN geode.zips AS r ON v._id = r._id LIMIT 1")
+ .returnsCount(1)
+ .explainContains("PLAN=EnumerableCalc(expr#0..2=[{inputs}], _id1=[$t0])\n"
+ + " EnumerableLimit(fetch=[1])\n"
+ + " EnumerableJoin(condition=[=($1, $2)], joinType=[inner])\n"
+ + " GeodeToEnumerableConverter\n"
+ + " GeodeProject(_id=[$0], _id0=[CAST($0):VARCHAR CHARACTER SET "
+ + "\"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n"
+ + " GeodeToEnumerableConverter\n"
+ + " GeodeProject(_id0=[CAST($0):VARCHAR CHARACTER SET \"ISO-8859-1\" COLLATE "
+ + "\"ISO-8859-1$en_US$primary\"])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+
+ @Test
+ public void testSelectLocItem() {
+ calciteAssert()
+ .query("SELECT loc[0] as lat, loc[1] as lon "
+ + "FROM view LIMIT 1")
+ .returns("lat=-105.007985; lon=39.840562\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
+ + " GeodeSort(fetch=[1])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+
+ @Test
+ public void testItemPredicate() {
+ calciteAssert()
+ .query("SELECT loc[0] as lat, loc[1] as lon "
+ + "FROM view WHERE loc[0] < 0 LIMIT 1")
+ .returnsCount(1)
+ .returns("lat=-105.007985; lon=39.840562\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
+ + " GeodeSort(fetch=[1])\n"
+ + " GeodeFilter(condition=[<(ITEM($2, 0), 0)])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+
+ calciteAssert()
+ .query("SELECT loc[0] as lat, loc[1] as lon "
+ + "FROM view WHERE loc[0] > 0 LIMIT 1")
+ .returnsCount(0)
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(lat=[ITEM($2, 0)], lon=[ITEM($2, 1)])\n"
+ + " GeodeSort(fetch=[1])\n"
+ + " GeodeFilter(condition=[>(ITEM($2, 0), 0)])\n"
+ + " GeodeTableScan(table=[[geode, zips]])\n");
+ }
+}
+
+// End GeodeZipsTest.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/JsonLoader.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/JsonLoader.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/JsonLoader.java
new file mode 100644
index 0000000..ea74b48
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/JsonLoader.java
@@ -0,0 +1,91 @@
+/*
+ * 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.adapter.geode.rel;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.pdx.PdxInstanceFactory;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Populates a geode region from a file having JSON entries (line by line).
+ */
+class JsonLoader {
+
+ private static final String ROOT_PACKATE = "org.apache.calcite.adapter.geode";
+
+ private final String rootPackage;
+ private final Region region;
+ private final ObjectMapper mapper;
+
+ JsonLoader(Region<?, ?> region) {
+ this.region = Objects.requireNonNull(region, "region");
+ this.rootPackage = ROOT_PACKATE;
+ this.mapper = new ObjectMapper();
+ }
+
+ private void load(Reader reader) throws IOException {
+ Objects.requireNonNull(reader, "reader");
+ try (BufferedReader br = new BufferedReader(reader)) {
+ int key = 0;
+ for (String line; (line = br.readLine()) != null;) {
+ Map jsonMap = mapper.readValue(line, Map.class);
+ PdxInstance pdxInstance = mapToPdx(rootPackage, jsonMap);
+ region.put(key++, pdxInstance);
+ }
+ }
+ }
+
+ void loadClasspathResource(String location) throws IOException {
+ Objects.requireNonNull(location, "location");
+ InputStream is = getClass().getResourceAsStream(location);
+ if (is == null) {
+ throw new IllegalArgumentException("Resource " + location + " not found in the classpath");
+ }
+
+ load(new InputStreamReader(is, StandardCharsets.UTF_8));
+ }
+
+ private PdxInstance mapToPdx(String packageName, Map<String, Object> map) {
+ PdxInstanceFactory pdxBuilder = region.getRegionService().createPdxInstanceFactory(packageName);
+
+ for (String name : map.keySet()) {
+ Object value = map.get(name);
+
+ if (value instanceof Map) {
+ pdxBuilder.writeObject(name, mapToPdx(packageName + "." + name, (Map) value));
+ } else {
+ pdxBuilder.writeObject(name, value);
+ }
+ }
+
+ return pdxBuilder.create();
+ }
+
+}
+
+// End JsonLoader.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/book_customer.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/book_customer.json b/geode/src/test/resources/book_customer.json
new file mode 100644
index 0000000..d32d20f
--- /dev/null
+++ b/geode/src/test/resources/book_customer.json
@@ -0,0 +1,3 @@
+{"customerNumber":5598,"firstName":"Kari","lastName":"Powell","primaryAddress":{"addressLine1":"123 Main St.","addressLine2":null,"addressLine3":null,"city":"Topeka","state":"KS","postalCode":"50505","country":"US","phoneNumber":"423-555-3322","addressTag":"HOME"},"myBookOrders":[17699,18009,18049]}
+{"customerNumber":5543,"firstName":"Lula","lastName":"Wax","primaryAddress":{"addressLine1":"123 Main St.","addressLine2":null,"addressLine3":null,"city":"Topeka","state":"KS","postalCode":"50505","country":"US","phoneNumber":"423-555-3322","addressTag":"HOME"},"myBookOrders":[17700]}
+{"customerNumber":6024,"firstName":"Trenton","lastName":"Garcia","primaryAddress":{"addressLine1":"123 Main St.","addressLine2":null,"addressLine3":null,"city":"San Francisco","state":"CA","postalCode":"50505","country":"US","phoneNumber":"423-555-3322","addressTag":"HOME"},"myBookOrders":[]}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/book_master.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/book_master.json b/geode/src/test/resources/book_master.json
new file mode 100644
index 0000000..5571971
--- /dev/null
+++ b/geode/src/test/resources/book_master.json
@@ -0,0 +1,3 @@
+{"itemNumber":123,"description":"Run on sentences and drivel on all things mundane","retailCost":34.99,"yearPublished":2011,"author":"Daisy Mae West","title":"A Treatise of Treatises"}
+{"itemNumber":456,"description":"A book about a dog","retailCost":11.99,"yearPublished":1971,"author":"Clarence Meeks","title":"Clifford the Big Red Dog"}
+{"itemNumber":789,"description":"Theoretical information about the structure of Operating Systems","retailCost":59.99,"yearPublished":2011,"author":"Jim Heavisides","title":"Operating Systems: An Introduction"}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/log4j.properties b/geode/src/test/resources/log4j.properties
new file mode 100644
index 0000000..a62b381
--- /dev/null
+++ b/geode/src/test/resources/log4j.properties
@@ -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.
+
+# Root logger is configured at INFO and is sent to A1
+log4j.rootLogger=INFO, A1
+
+log4j.logger.org.apache.calcite.adapter.geode=WARN
+
+# A1 goes to the console
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# 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/ed424ed8/geode/src/test/resources/model-bookshop-all.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model-bookshop-all.json b/geode/src/test/resources/model-bookshop-all.json
deleted file mode 100644
index 13ed2e5..0000000
--- a/geode/src/test/resources/model-bookshop-all.json
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "TEST",
- "schemas": [
- {
- "name": "TEST",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "BookMaster,BookCustomer,BookOrder,BookInventory",
- "pdxSerializablePackagePath": "org.apache.calcite.adapter.geode.domain.bookshop.*"
- }
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model-bookshop.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model-bookshop.json b/geode/src/test/resources/model-bookshop.json
deleted file mode 100644
index aaab978..0000000
--- a/geode/src/test/resources/model-bookshop.json
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "TEST",
- "schemas": [
- {
- "name": "TEST",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "BookMaster,BookCustomer",
- "pdxSerializablePackagePath": "org.apache.calcite.adapter.geode.*"
- }
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model-geode-pg-federation.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model-geode-pg-federation.json b/geode/src/test/resources/model-geode-pg-federation.json
deleted file mode 100644
index 586fafa..0000000
--- a/geode/src/test/resources/model-geode-pg-federation.json
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "geode",
- "schemas": [
- {
- "type": "custom",
- "name": "geode_zips",
- "factory": "org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "Zips",
- "pdxSerializablePackagePath": ".*"
- }
- },
- {
- "type": "jdbc",
- "name": "mysql_foodmart",
- "jdbcUser": "foodmart",
- "jdbcPassword": "foodmart",
- "jdbcUrl": "jdbc:mysql://localhost",
- "jdbcCatalog": "foodmart",
- "jdbcSchema": null
- },
- {
- "type": "jdbc",
- "name": "postgresql_foodmart",
- "jdbcUser": "foodmart",
- "jdbcPassword": "foodmart",
- "jdbcDriver": "org.postgresql.Driver",
- "jdbcUrl": "jdbc:postgresql://localhost/foodmart",
- "jdbcCatalog": "foodmart",
- "jdbcSchema": null
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model-with-classes.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model-with-classes.json b/geode/src/test/resources/model-with-classes.json
deleted file mode 100644
index b776f0e..0000000
--- a/geode/src/test/resources/model-with-classes.json
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "TEST",
- "schemas": [
- {
- "name": "TEST",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.simple.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "BookMaster,Customer,InventoryItem,BookOrder",
- "BookMaster": "net.tzolov.geode.bookstore.domain.BookMaster",
- "Customer": "net.tzolov.geode.bookstore.domain.Customer",
- "InventoryItem": "net.tzolov.geode.bookstore.domain.InventoryItem",
- "BookOrder": "net.tzolov.geode.bookstore.domain.BookOrder",
- "pdxSerializablePackagePath": "net.tzolov.geode.bookstore.domain.*"
- }
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model-zips.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model-zips.json b/geode/src/test/resources/model-zips.json
deleted file mode 100644
index 4077768..0000000
--- a/geode/src/test/resources/model-zips.json
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "geode_raw",
- "schemas": [
- {
- "name": "geode_raw",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "Zips",
- "pdxSerializablePackagePath": ".*"
- }
- },
- {
- "name": "geode",
- "tables": [
- {
- "name": "ZIPS",
- "type": "view",
- "sql": [
- "select \"_id\" AS \"id\", \"city\", \"loc\", cast(\"pop\" AS integer) AS \"pop\", cast(\"state\" AS varchar(2)) AS \"state\" from \"geode_raw\".\"Zips\""
- ]
- }
- ]
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model.json b/geode/src/test/resources/model.json
deleted file mode 100644
index c1a2c86..0000000
--- a/geode/src/test/resources/model.json
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "TEST",
- "schemas": [
- {
- "name": "TEST",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.simple.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "BookMaster",
- "pdxSerializablePackagePath": "net.tzolov.geode.bookstore.domain.*"
- }
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/model2.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/model2.json b/geode/src/test/resources/model2.json
deleted file mode 100644
index 4cbe328..0000000
--- a/geode/src/test/resources/model2.json
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- *
- * A JSON model of a simple Calcite schema.
- */
-{
- "version": "1.0",
- "defaultSchema": "TEST",
- "schemas": [
- {
- "name": "TEST",
- "type": "custom",
- "factory": "org.apache.calcite.adapter.geode.simple.GeodeSchemaFactory",
- "operand": {
- "locatorHost": "localhost",
- "locatorPort": "10334",
- "regions": "BookMaster,Customer,InventoryItem,BookOrder",
- "pdxSerializablePackagePath": "net.tzolov.geode.bookstore.domain.*"
- }
- }
- ]
-}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/resources/zips-mini.json
----------------------------------------------------------------------
diff --git a/geode/src/test/resources/zips-mini.json b/geode/src/test/resources/zips-mini.json
new file mode 100644
index 0000000..858117a
--- /dev/null
+++ b/geode/src/test/resources/zips-mini.json
@@ -0,0 +1,149 @@
+{ "_id" : "01701", "city" : "FRAMINGHAM", "loc" : [ -71.42548600000001, 42.300665 ], "pop" : 65046, "state" : "MA" }
+{ "_id" : "02154", "city" : "NORTH WALTHAM", "loc" : [ -71.236497, 42.382492 ], "pop" : 57871, "state" : "MA" }
+{ "_id" : "02401", "city" : "BROCKTON", "loc" : [ -71.03434799999999, 42.081571 ], "pop" : 59498, "state" : "MA" }
+{ "_id" : "02840", "city" : "MIDDLETOWN", "loc" : [ -71.30347999999999, 41.504502 ], "pop" : 47687, "state" : "RI" }
+{ "_id" : "02860", "city" : "PAWTUCKET", "loc" : [ -71.39071300000001, 41.872873 ], "pop" : 45442, "state" : "RI" }
+{ "_id" : "02895", "city" : "NORTH SMITHFIELD", "loc" : [ -71.513683, 41.99948 ], "pop" : 53733, "state" : "RI" }
+{ "_id" : "03060", "city" : "NASHUA", "loc" : [ -71.466684, 42.756395 ], "pop" : 41438, "state" : "NH" }
+{ "_id" : "03103", "city" : "MANCHESTER", "loc" : [ -71.449325, 42.965563 ], "pop" : 36613, "state" : "NH" }
+{ "_id" : "03301", "city" : "CONCORD", "loc" : [ -71.527734, 43.218525 ], "pop" : 34035, "state" : "NH" }
+{ "_id" : "04240", "city" : "LEWISTON", "loc" : [ -70.191619, 44.098538 ], "pop" : 40173, "state" : "ME" }
+{ "_id" : "04401", "city" : "BANGOR", "loc" : [ -68.791839, 44.824199 ], "pop" : 40434, "state" : "ME" }
+{ "_id" : "05301", "city" : "BRATTLEBORO", "loc" : [ -72.593322, 42.857353 ], "pop" : 17522, "state" : "VT" }
+{ "_id" : "05401", "city" : "BURLINGTON", "loc" : [ -73.219875, 44.484023 ], "pop" : 39127, "state" : "VT" }
+{ "_id" : "05701", "city" : "RUTLAND", "loc" : [ -72.97077299999999, 43.614131 ], "pop" : 22576, "state" : "VT" }
+{ "_id" : "06010", "city" : "BRISTOL", "loc" : [ -72.930193, 41.682293 ], "pop" : 60670, "state" : "CT" }
+{ "_id" : "06450", "city" : "MERIDEN", "loc" : [ -72.799734, 41.533396 ], "pop" : 59441, "state" : "CT" }
+{ "_id" : "06902", "city" : "STAMFORD", "loc" : [ -73.53742800000001, 41.052552 ], "pop" : 54605, "state" : "CT" }
+{ "_id" : "07002", "city" : "BAYONNE", "loc" : [ -74.119169, 40.666399 ], "pop" : 61444, "state" : "NJ" }
+{ "_id" : "07087", "city" : "WEEHAWKEN", "loc" : [ -74.030558, 40.768153 ], "pop" : 69646, "state" : "NJ" }
+{ "_id" : "07111", "city" : "IRVINGTON", "loc" : [ -74.23127100000001, 40.7261 ], "pop" : 60986, "state" : "NJ" }
+{ "_id" : "10021", "city" : "NEW YORK", "loc" : [ -73.958805, 40.768476 ], "pop" : 106564, "state" : "NY" }
+{ "_id" : "11226", "city" : "BROOKLYN", "loc" : [ -73.956985, 40.646694 ], "pop" : 111396, "state" : "NY" }
+{ "_id" : "11373", "city" : "JACKSON HEIGHTS", "loc" : [ -73.878551, 40.740388 ], "pop" : 88241, "state" : "NY" }
+{ "_id" : "17042", "city" : "CLEONA", "loc" : [ -76.425895, 40.335912 ], "pop" : 61993, "state" : "PA" }
+{ "_id" : "18042", "city" : "FORKS TOWNSHIP", "loc" : [ -75.23582, 40.6867 ], "pop" : 65784, "state" : "PA" }
+{ "_id" : "19143", "city" : "PHILADELPHIA", "loc" : [ -75.228819, 39.944815 ], "pop" : 80454, "state" : "PA" }
+{ "_id" : "19711", "city" : "NEWARK", "loc" : [ -75.737534, 39.701129 ], "pop" : 50573, "state" : "DE" }
+{ "_id" : "19720", "city" : "MANOR", "loc" : [ -75.589938, 39.67703 ], "pop" : 46906, "state" : "DE" }
+{ "_id" : "19901", "city" : "DOVER", "loc" : [ -75.535983, 39.156639 ], "pop" : 46005, "state" : "DE" }
+{ "_id" : "20011", "city" : "WASHINGTON", "loc" : [ -77.020251, 38.951786 ], "pop" : 62924, "state" : "DC" }
+{ "_id" : "20301", "city" : "PENTAGON", "loc" : [ -77.038196, 38.891019 ], "pop" : 21, "state" : "DC" }
+{ "_id" : "21061", "city" : "GLEN BURNIE", "loc" : [ -76.61886199999999, 39.158968 ], "pop" : 75692, "state" : "MD" }
+{ "_id" : "21207", "city" : "GWYNN OAK", "loc" : [ -76.734064, 39.329628 ], "pop" : 76002, "state" : "MD" }
+{ "_id" : "21215", "city" : "BALTIMORE", "loc" : [ -76.67939699999999, 39.344572 ], "pop" : 74402, "state" : "MD" }
+{ "_id" : "22901", "city" : "CHARLOTTESVILLE", "loc" : [ -78.490869, 38.054752 ], "pop" : 62708, "state" : "VA" }
+{ "_id" : "23464", "city" : "VIRGINIA BEACH", "loc" : [ -76.175909, 36.797772 ], "pop" : 67276, "state" : "VA" }
+{ "_id" : "23602", "city" : "NEWPORT NEWS", "loc" : [ -76.53212499999999, 37.131684 ], "pop" : 68525, "state" : "VA" }
+{ "_id" : "25801", "city" : "BECKLEY", "loc" : [ -81.206084, 37.793214 ], "pop" : 45196, "state" : "WV" }
+{ "_id" : "26003", "city" : "ELM GROVE", "loc" : [ -80.685126, 40.072736 ], "pop" : 49136, "state" : "WV" }
+{ "_id" : "26505", "city" : "STAR CITY", "loc" : [ -79.95422499999999, 39.633858 ], "pop" : 70185, "state" : "WV" }
+{ "_id" : "27292", "city" : "LEXINGTON", "loc" : [ -80.262049, 35.82306 ], "pop" : 69179, "state" : "NC" }
+{ "_id" : "28677", "city" : "STATESVILLE", "loc" : [ -80.894009, 35.799022 ], "pop" : 52895, "state" : "NC" }
+{ "_id" : "29150", "city" : "OSWEGO", "loc" : [ -80.32100800000001, 33.928199 ], "pop" : 46394, "state" : "SC" }
+{ "_id" : "29501", "city" : "FLORENCE", "loc" : [ -79.772786, 34.18375 ], "pop" : 66990, "state" : "SC" }
+{ "_id" : "29801", "city" : "AIKEN", "loc" : [ -81.71942900000001, 33.553024 ], "pop" : 51233, "state" : "SC" }
+{ "_id" : "30032", "city" : "DECATUR", "loc" : [ -84.263165, 33.740825 ], "pop" : 56056, "state" : "GA" }
+{ "_id" : "30906", "city" : "PEACH ORCHARD", "loc" : [ -82.038358, 33.402024 ], "pop" : 58646, "state" : "GA" }
+{ "_id" : "32216", "city" : "JACKSONVILLE", "loc" : [ -81.547387, 30.293907 ], "pop" : 58867, "state" : "FL" }
+{ "_id" : "33012", "city" : "HIALEAH", "loc" : [ -80.30589999999999, 25.865395 ], "pop" : 73194, "state" : "FL" }
+{ "_id" : "33311", "city" : "FORT LAUDERDALE", "loc" : [ -80.172786, 26.142104 ], "pop" : 65378, "state" : "FL" }
+{ "_id" : "35215", "city" : "CENTER POINT", "loc" : [ -86.693197, 33.635447 ], "pop" : 43862, "state" : "AL" }
+{ "_id" : "35401", "city" : "TUSCALOOSA", "loc" : [ -87.56266599999999, 33.196891 ], "pop" : 42124, "state" : "AL" }
+{ "_id" : "35901", "city" : "SOUTHSIDE", "loc" : [ -86.010279, 33.997248 ], "pop" : 44165, "state" : "AL" }
+{ "_id" : "37042", "city" : "CLARKSVILLE", "loc" : [ -87.418621, 36.585315 ], "pop" : 43296, "state" : "TN" }
+{ "_id" : "37211", "city" : "NASHVILLE", "loc" : [ -86.72403799999999, 36.072486 ], "pop" : 51478, "state" : "TN" }
+{ "_id" : "38109", "city" : "MEMPHIS", "loc" : [ -90.073238, 35.042538 ], "pop" : 60508, "state" : "TN" }
+{ "_id" : "39180", "city" : "VICKSBURG", "loc" : [ -90.85065, 32.325824 ], "pop" : 46968, "state" : "MS" }
+{ "_id" : "39401", "city" : "HATTIESBURG", "loc" : [ -89.306471, 31.314553 ], "pop" : 41866, "state" : "MS" }
+{ "_id" : "39440", "city" : "LAUREL", "loc" : [ -89.13115500000001, 31.705444 ], "pop" : 45040, "state" : "MS" }
+{ "_id" : "40214", "city" : "LOUISVILLE", "loc" : [ -85.77802699999999, 38.159318 ], "pop" : 42198, "state" : "KY" }
+{ "_id" : "40216", "city" : "SHIVELY", "loc" : [ -85.831771, 38.186138 ], "pop" : 41719, "state" : "KY" }
+{ "_id" : "40601", "city" : "HATTON", "loc" : [ -84.88061, 38.192831 ], "pop" : 46563, "state" : "KY" }
+{ "_id" : "44035", "city" : "ELYRIA", "loc" : [ -82.10508799999999, 41.372353 ], "pop" : 66674, "state" : "OH" }
+{ "_id" : "44060", "city" : "MENTOR", "loc" : [ -81.342133, 41.689468 ], "pop" : 60109, "state" : "OH" }
+{ "_id" : "44107", "city" : "EDGEWATER", "loc" : [ -81.79714300000001, 41.482654 ], "pop" : 59702, "state" : "OH" }
+{ "_id" : "46360", "city" : "MICHIGAN CITY", "loc" : [ -86.869899, 41.698031 ], "pop" : 55392, "state" : "IN" }
+{ "_id" : "47130", "city" : "JEFFERSONVILLE", "loc" : [ -85.735885, 38.307767 ], "pop" : 56543, "state" : "IN" }
+{ "_id" : "47906", "city" : "WEST LAFAYETTE", "loc" : [ -86.923661, 40.444025 ], "pop" : 54702, "state" : "IN" }
+{ "_id" : "48180", "city" : "TAYLOR", "loc" : [ -83.267269, 42.231738 ], "pop" : 70811, "state" : "MI" }
+{ "_id" : "48185", "city" : "WESTLAND", "loc" : [ -83.374908, 42.318882 ], "pop" : 84712, "state" : "MI" }
+{ "_id" : "48227", "city" : "DETROIT", "loc" : [ -83.193732, 42.388303 ], "pop" : 68390, "state" : "MI" }
+{ "_id" : "50010", "city" : "AMES", "loc" : [ -93.639398, 42.029859 ], "pop" : 52105, "state" : "IA" }
+{ "_id" : "50317", "city" : "PLEASANT HILL", "loc" : [ -93.549446, 41.612499 ], "pop" : 39883, "state" : "IA" }
+{ "_id" : "52001", "city" : "DUBUQUE", "loc" : [ -90.68191400000001, 42.514977 ], "pop" : 41934, "state" : "IA" }
+{ "_id" : "53209", "city" : "MILWAUKEE", "loc" : [ -87.947834, 43.118765 ], "pop" : 51008, "state" : "WI" }
+{ "_id" : "54401", "city" : "WAUSAU", "loc" : [ -89.633955, 44.963433 ], "pop" : 51083, "state" : "WI" }
+{ "_id" : "54901", "city" : "OSHKOSH", "loc" : [ -88.54363499999999, 44.021962 ], "pop" : 57187, "state" : "WI" }
+{ "_id" : "55106", "city" : "SAINT PAUL", "loc" : [ -93.048817, 44.968384 ], "pop" : 47905, "state" : "MN" }
+{ "_id" : "55112", "city" : "NEW BRIGHTON", "loc" : [ -93.199691, 45.074129 ], "pop" : 44128, "state" : "MN" }
+{ "_id" : "55337", "city" : "BURNSVILLE", "loc" : [ -93.275283, 44.76086 ], "pop" : 51421, "state" : "MN" }
+{ "_id" : "57103", "city" : "SIOUX FALLS", "loc" : [ -96.686415, 43.537386 ], "pop" : 32508, "state" : "SD" }
+{ "_id" : "57401", "city" : "ABERDEEN", "loc" : [ -98.485642, 45.466109 ], "pop" : 28786, "state" : "SD" }
+{ "_id" : "57701", "city" : "ROCKERVILLE", "loc" : [ -103.200259, 44.077041 ], "pop" : 45328, "state" : "SD" }
+{ "_id" : "58103", "city" : "FARGO", "loc" : [ -96.812252, 46.856406 ], "pop" : 38483, "state" : "ND" }
+{ "_id" : "58501", "city" : "BISMARCK", "loc" : [ -100.774755, 46.823448 ], "pop" : 36602, "state" : "ND" }
+{ "_id" : "58701", "city" : "MINOT", "loc" : [ -101.298476, 48.22914 ], "pop" : 42195, "state" : "ND" }
+{ "_id" : "59102", "city" : "BILLINGS", "loc" : [ -108.572662, 45.781265 ], "pop" : 40121, "state" : "MT" }
+{ "_id" : "59601", "city" : "HELENA", "loc" : [ -112.021283, 46.613066 ], "pop" : 40102, "state" : "MT" }
+{ "_id" : "59801", "city" : "MISSOULA", "loc" : [ -114.025207, 46.856274 ], "pop" : 33811, "state" : "MT" }
+{ "_id" : "60623", "city" : "CHICAGO", "loc" : [ -87.7157, 41.849015 ], "pop" : 112047, "state" : "IL" }
+{ "_id" : "60634", "city" : "NORRIDGE", "loc" : [ -87.796054, 41.945213 ], "pop" : 69160, "state" : "IL" }
+{ "_id" : "60650", "city" : "CICERO", "loc" : [ -87.76008, 41.84776 ], "pop" : 67670, "state" : "IL" }
+{ "_id" : "63031", "city" : "FLORISSANT", "loc" : [ -90.340097, 38.806865 ], "pop" : 52659, "state" : "MO" }
+{ "_id" : "63116", "city" : "SAINT LOUIS", "loc" : [ -90.26254299999999, 38.581356 ], "pop" : 49014, "state" : "MO" }
+{ "_id" : "63136", "city" : "JENNINGS", "loc" : [ -90.260189, 38.738878 ], "pop" : 54994, "state" : "MO" }
+{ "_id" : "66502", "city" : "MANHATTAN", "loc" : [ -96.585776, 39.193757 ], "pop" : 50178, "state" : "KS" }
+{ "_id" : "67212", "city" : "WICHITA", "loc" : [ -97.438344, 37.700683 ], "pop" : 41349, "state" : "KS" }
+{ "_id" : "67401", "city" : "BAVARIA", "loc" : [ -97.60878700000001, 38.823802 ], "pop" : 45208, "state" : "KS" }
+{ "_id" : "68104", "city" : "OMAHA", "loc" : [ -95.999888, 41.29186 ], "pop" : 35325, "state" : "NE" }
+{ "_id" : "68502", "city" : "LINCOLN", "loc" : [ -96.693763, 40.789282 ], "pop" : 27576, "state" : "NE" }
+{ "_id" : "68847", "city" : "KEARNEY", "loc" : [ -99.077883, 40.713608 ], "pop" : 28674, "state" : "NE" }
+{ "_id" : "70072", "city" : "MARRERO", "loc" : [ -90.110462, 29.859756 ], "pop" : 58905, "state" : "LA" }
+{ "_id" : "70117", "city" : "NEW ORLEANS", "loc" : [ -90.03124, 29.970298 ], "pop" : 56494, "state" : "LA" }
+{ "_id" : "70560", "city" : "NEW IBERIA", "loc" : [ -91.819959, 30.001027 ], "pop" : 56105, "state" : "LA" }
+{ "_id" : "72032", "city" : "CONWAY", "loc" : [ -92.423574, 35.084199 ], "pop" : 43236, "state" : "AR" }
+{ "_id" : "72076", "city" : "GRAVEL RIDGE", "loc" : [ -92.13043500000001, 34.881985 ], "pop" : 37428, "state" : "AR" }
+{ "_id" : "72401", "city" : "JONESBORO", "loc" : [ -90.69652600000001, 35.833016 ], "pop" : 53532, "state" : "AR" }
+{ "_id" : "73034", "city" : "EDMOND", "loc" : [ -97.47983499999999, 35.666483 ], "pop" : 43814, "state" : "OK" }
+{ "_id" : "73505", "city" : "LAWTON", "loc" : [ -98.455234, 34.617939 ], "pop" : 45542, "state" : "OK" }
+{ "_id" : "74801", "city" : "SHAWNEE", "loc" : [ -96.931321, 35.34907 ], "pop" : 40076, "state" : "OK" }
+{ "_id" : "78207", "city" : "SAN ANTONIO", "loc" : [ -98.52596699999999, 29.422855 ], "pop" : 58355, "state" : "TX" }
+{ "_id" : "78521", "city" : "BROWNSVILLE", "loc" : [ -97.461236, 25.922103 ], "pop" : 79463, "state" : "TX" }
+{ "_id" : "78572", "city" : "ALTON", "loc" : [ -98.342647, 26.24153 ], "pop" : 67604, "state" : "TX" }
+{ "_id" : "80123", "city" : "BOW MAR", "loc" : [ -105.07766, 39.596854 ], "pop" : 59418, "state" : "CO" }
+{ "_id" : "80221", "city" : "FEDERAL HEIGHTS", "loc" : [ -105.007985, 39.840562 ], "pop" : 54069, "state" : "CO" }
+{ "_id" : "80631", "city" : "GARDEN CITY", "loc" : [ -104.704756, 40.413968 ], "pop" : 53905, "state" : "CO" }
+{ "_id" : "82001", "city" : "CHEYENNE", "loc" : [ -104.796234, 41.143719 ], "pop" : 33107, "state" : "WY" }
+{ "_id" : "82070", "city" : "LARAMIE", "loc" : [ -105.581146, 41.312907 ], "pop" : 29327, "state" : "WY" }
+{ "_id" : "82716", "city" : "GILLETTE", "loc" : [ -105.497442, 44.282009 ], "pop" : 25968, "state" : "WY" }
+{ "_id" : "83301", "city" : "TWIN FALLS", "loc" : [ -114.469265, 42.556495 ], "pop" : 34539, "state" : "ID" }
+{ "_id" : "83704", "city" : "BOISE", "loc" : [ -116.295099, 43.633001 ], "pop" : 40912, "state" : "ID" }
+{ "_id" : "83814", "city" : "COEUR D ALENE", "loc" : [ -116.784976, 47.692841 ], "pop" : 33589, "state" : "ID" }
+{ "_id" : "84118", "city" : "KEARNS", "loc" : [ -111.98521, 40.652759 ], "pop" : 55999, "state" : "UT" }
+{ "_id" : "84120", "city" : "WEST VALLEY CITY", "loc" : [ -112.009783, 40.68708 ], "pop" : 52854, "state" : "UT" }
+{ "_id" : "84604", "city" : "PROVO", "loc" : [ -111.654906, 40.260681 ], "pop" : 43841, "state" : "UT" }
+{ "_id" : "85023", "city" : "PHOENIX", "loc" : [ -112.111838, 33.632383 ], "pop" : 54668, "state" : "AZ" }
+{ "_id" : "85204", "city" : "MESA", "loc" : [ -111.789554, 33.399168 ], "pop" : 55180, "state" : "AZ" }
+{ "_id" : "85364", "city" : "YUMA", "loc" : [ -114.642362, 32.701507 ], "pop" : 57131, "state" : "AZ" }
+{ "_id" : "87501", "city" : "POJOAQUE VALLEY", "loc" : [ -105.974818, 35.702472 ], "pop" : 51715, "state" : "NM" }
+{ "_id" : "88001", "city" : "LAS CRUCES", "loc" : [ -106.746034, 32.321641 ], "pop" : 57502, "state" : "NM" }
+{ "_id" : "88201", "city" : "ROSWELL", "loc" : [ -104.525857, 33.388504 ], "pop" : 53644, "state" : "NM" }
+{ "_id" : "89031", "city" : "NORTH LAS VEGAS", "loc" : [ -115.124832, 36.206228 ], "pop" : 48113, "state" : "NV" }
+{ "_id" : "89115", "city" : "LAS VEGAS", "loc" : [ -115.067062, 36.215818 ], "pop" : 51532, "state" : "NV" }
+{ "_id" : "89502", "city" : "RENO", "loc" : [ -119.776395, 39.497239 ], "pop" : 38332, "state" : "NV" }
+{ "_id" : "90011", "city" : "LOS ANGELES", "loc" : [ -118.258189, 34.007856 ], "pop" : 96074, "state" : "CA" }
+{ "_id" : "90201", "city" : "BELL GARDENS", "loc" : [ -118.17205, 33.969177 ], "pop" : 99568, "state" : "CA" }
+{ "_id" : "90650", "city" : "NORWALK", "loc" : [ -118.081767, 33.90564 ], "pop" : 94188, "state" : "CA" }
+{ "_id" : "96734", "city" : "KAILUA", "loc" : [ -157.744781, 21.406262 ], "pop" : 53403, "state" : "HI" }
+{ "_id" : "96744", "city" : "KANEOHE", "loc" : [ -157.811543, 21.422819 ], "pop" : 55236, "state" : "HI" }
+{ "_id" : "96818", "city" : "HONOLULU", "loc" : [ -157.926925, 21.353173 ], "pop" : 62915, "state" : "HI" }
+{ "_id" : "97005", "city" : "BEAVERTON", "loc" : [ -122.805395, 45.475035 ], "pop" : 46660, "state" : "OR" }
+{ "_id" : "97206", "city" : "PORTLAND", "loc" : [ -122.59727, 45.483995 ], "pop" : 43134, "state" : "OR" }
+{ "_id" : "97301", "city" : "SALEM", "loc" : [ -122.979692, 44.926039 ], "pop" : 48007, "state" : "OR" }
+{ "_id" : "98031", "city" : "KENT", "loc" : [ -122.193184, 47.388004 ], "pop" : 50515, "state" : "WA" }
+{ "_id" : "98059", "city" : "RENTON", "loc" : [ -122.151178, 47.467383 ], "pop" : 48197, "state" : "WA" }
+{ "_id" : "98310", "city" : "BREMERTON", "loc" : [ -122.629913, 47.601916 ], "pop" : 49057, "state" : "WA" }
+{ "_id" : "99504", "city" : "ANCHORAGE", "loc" : [ -149.74467, 61.203696 ], "pop" : 32383, "state" : "AK" }
+{ "_id" : "99709", "city" : "FAIRBANKS", "loc" : [ -147.846917, 64.85437 ], "pop" : 23238, "state" : "AK" }
+{ "_id" : "99801", "city" : "JUNEAU", "loc" : [ -134.529429, 58.362767 ], "pop" : 24947, "state" : "AK" }
[2/2] calcite git commit: [CALCITE-2588] Run Geode Adapter tests with
an Embedded Instance
Posted by se...@apache.org.
[CALCITE-2588] Run Geode Adapter tests with an Embedded Instance
Part of the effort to increase test coverage for adapters. Enables execution of all Geode adapter tests during CI build (instead of manual run).
Create special JUnit Rule (`GeodeEmbeddedPolicy`) which starts / stops embedded Geode instance once for all the tests.
Modify GeodeSchema and GeodeTable to accept exising geode instance in the constructor instance of connection parameters.
Ignore two tests which currently fail for both embedded and external instance(s). These bugs will be addressed separately
Local test dataset is taken from `calcite-test-dataset` project (the one which is used for integration testing). Re-use `zips-mini.json` from mongo/elastic adapters.
Closes apache/calcite#857
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/ed424ed8
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/ed424ed8
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/ed424ed8
Branch: refs/heads/master
Commit: ed424ed81d0de66fcfd6a5352f00fb99cc514882
Parents: 9ba9bdc
Author: Andrei Sereda <25...@users.noreply.github.com>
Authored: Thu Sep 13 11:37:20 2018 -0400
Committer: Andrei Sereda <25...@users.noreply.github.com>
Committed: Tue Sep 25 14:04:36 2018 -0400
----------------------------------------------------------------------
geode/pom.xml | 5 +
.../adapter/geode/rel/GeodeAggregate.java | 17 +-
.../calcite/adapter/geode/rel/GeodeFilter.java | 4 +-
.../calcite/adapter/geode/rel/GeodeProject.java | 5 +-
.../calcite/adapter/geode/rel/GeodeRel.java | 8 +-
.../calcite/adapter/geode/rel/GeodeRules.java | 7 +-
.../calcite/adapter/geode/rel/GeodeSchema.java | 47 +-
.../adapter/geode/rel/GeodeSchemaFactory.java | 5 +-
.../calcite/adapter/geode/rel/GeodeSort.java | 9 +-
.../calcite/adapter/geode/rel/GeodeTable.java | 68 +--
.../adapter/geode/rel/GeodeTableScan.java | 2 +-
.../geode/rel/GeodeToEnumerableConverter.java | 13 +-
.../adapter/geode/simple/GeodeSimpleSchema.java | 9 +-
.../calcite/adapter/geode/util/GeodeUtils.java | 60 ++-
.../adapter/geode/rel/AbstractGeodeTest.java | 33 ++
.../adapter/geode/rel/BaseGeodeAdapterIT.java | 159 ------
.../geode/rel/GeodeAdapterBookshopIT.java | 469 ------------------
.../adapter/geode/rel/GeodeAdapterIT.java | 99 ----
.../adapter/geode/rel/GeodeAssertions.java | 44 ++
.../adapter/geode/rel/GeodeBookstoreTest.java | 483 +++++++++++++++++++
.../adapter/geode/rel/GeodeEmbeddedPolicy.java | 154 ++++++
.../calcite/adapter/geode/rel/GeodeZipsIT.java | 200 --------
.../adapter/geode/rel/GeodeZipsTest.java | 191 ++++++++
.../calcite/adapter/geode/rel/JsonLoader.java | 91 ++++
geode/src/test/resources/book_customer.json | 3 +
geode/src/test/resources/book_master.json | 3 +
geode/src/test/resources/log4j.properties | 26 +
.../src/test/resources/model-bookshop-all.json | 35 --
geode/src/test/resources/model-bookshop.json | 35 --
.../resources/model-geode-pg-federation.json | 54 ---
.../src/test/resources/model-with-classes.json | 39 --
geode/src/test/resources/model-zips.json | 47 --
geode/src/test/resources/model.json | 35 --
geode/src/test/resources/model2.json | 35 --
geode/src/test/resources/zips-mini.json | 149 ++++++
35 files changed, 1323 insertions(+), 1320 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/pom.xml
----------------------------------------------------------------------
diff --git a/geode/pom.xml b/geode/pom.xml
index 698ca72..a9e24de 100644
--- a/geode/pom.xml
+++ b/geode/pom.xml
@@ -89,6 +89,11 @@ limitations under the License.
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeAggregate.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeAggregate.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeAggregate.java
index faab698..19bbe63 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeAggregate.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeAggregate.java
@@ -76,21 +76,14 @@ public class GeodeAggregate extends Aggregate implements GeodeRel {
}
@Override public void implement(GeodeImplementContext geodeImplementContext) {
-
- ((GeodeRel) getInput()).implement(geodeImplementContext);
+ geodeImplementContext.visitChild(getInput());
List<String> inputFields = fieldNames(getInput().getRowType());
List<String> groupByFields = new ArrayList<>();
- // GROUP BY field == cardinality of 1, GROUP BY field1, field2 => cardinality of 2 ...
- if (groupSet.cardinality() == 1) {
- final String groupByFieldName = inputFields.get(groupSet.nth(0));
- groupByFields.add(groupByFieldName);
- } else {
- for (int group : groupSet) {
- groupByFields.add(inputFields.get(group));
- }
+ for (int group : groupSet) {
+ groupByFields.add(inputFields.get(group));
}
geodeImplementContext.addGroupBy(groupByFields);
@@ -99,7 +92,7 @@ public class GeodeAggregate extends Aggregate implements GeodeRel {
Builder<String, String> aggregateFunctionMap = ImmutableMap.builder();
for (AggregateCall aggCall : aggCalls) {
- ArrayList<Object> aggCallFieldNames = new ArrayList<>();
+ List<String> aggCallFieldNames = new ArrayList<>();
for (int i : aggCall.getArgList()) {
aggCallFieldNames.add(inputFields.get(i));
}
@@ -112,7 +105,7 @@ public class GeodeAggregate extends Aggregate implements GeodeRel {
aggCallFieldNames.add(inputFields.get(0));
}
- String oqlAggregateCall = Util.toString(aggCallFieldNames, " " + functionName + "(", ", ",
+ String oqlAggregateCall = Util.toString(aggCallFieldNames, functionName + "(", ", ",
")");
aggregateFunctionMap.put(aggCall.getName(), oqlAggregateCall);
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java
index e69a0db..203e5fe 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java
@@ -48,7 +48,7 @@ public class GeodeFilter extends Filter implements GeodeRel {
private final String match;
- public GeodeFilter(RelOptCluster cluster, RelTraitSet traitSet,
+ GeodeFilter(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, RexNode condition) {
super(cluster, traitSet, input, condition);
@@ -70,7 +70,7 @@ public class GeodeFilter extends Filter implements GeodeRel {
@Override public void implement(GeodeImplementContext geodeImplementContext) {
// first call the input down the tree.
- ((GeodeRel) getInput()).implement(geodeImplementContext);
+ geodeImplementContext.visitChild(getInput());
geodeImplementContext.addPredicates(Collections.singletonList(match));
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeProject.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeProject.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeProject.java
index c8f328c..990a70c 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeProject.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeProject.java
@@ -39,7 +39,7 @@ import java.util.Map;
*/
public class GeodeProject extends Project implements GeodeRel {
- public GeodeProject(RelOptCluster cluster, RelTraitSet traitSet,
+ GeodeProject(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, List<? extends RexNode> projects, RelDataType rowType) {
super(cluster, traitSet, input, projects, rowType);
assert getConvention() == GeodeRel.CONVENTION;
@@ -56,8 +56,7 @@ public class GeodeProject extends Project implements GeodeRel {
}
@Override public void implement(GeodeImplementContext geodeImplementContext) {
-
- ((GeodeRel) getInput()).implement(geodeImplementContext);
+ geodeImplementContext.visitChild(getInput());
final RexToGeodeTranslator translator =
new RexToGeodeTranslator(
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRel.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRel.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRel.java
index ebf1d0d..30a150e 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRel.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRel.java
@@ -61,7 +61,7 @@ public interface GeodeRel extends RelNode {
final Map<String, String> oqlAggregateFunctions = new LinkedHashMap<>();
- String limitValue = null;
+ Long limitValue;
RelOptTable table;
@@ -93,7 +93,7 @@ public interface GeodeRel extends RelNode {
orderByFields.addAll(orderByFieldLists);
}
- public void setLimit(String limit) {
+ public void setLimit(long limit) {
limitValue = limit;
}
@@ -105,6 +105,10 @@ public interface GeodeRel extends RelNode {
this.oqlAggregateFunctions.putAll(oqlAggregateFunctions);
}
+ void visitChild(RelNode input) {
+ ((GeodeRel) input).implement(this);
+ }
+
@Override public String toString() {
return "GeodeImplementContext{"
+ "selectFields=" + selectFields
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java
index 0e006eb..a0e7b0a 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java
@@ -49,13 +49,14 @@ import java.util.function.Predicate;
*/
public class GeodeRules {
- public static final RelOptRule[] RULES = {
+ static final RelOptRule[] RULES = {
+ GeodeSortLimitRule.INSTANCE,
GeodeFilterRule.INSTANCE,
GeodeProjectRule.INSTANCE,
- GeodeSortLimitRule.INSTANCE,
- GeodeAggregateRule.INSTANCE
+ GeodeAggregateRule.INSTANCE,
};
+
private GeodeRules() {
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchema.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchema.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchema.java
index 2e38741..0a099a2 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchema.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchema.java
@@ -17,45 +17,40 @@
package org.apache.calcite.adapter.geode.rel;
import org.apache.calcite.adapter.geode.util.GeodeUtils;
-import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractSchema;
-import org.apache.calcite.util.trace.CalciteTrace;
+import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import org.slf4j.Logger;
-
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
import static org.apache.calcite.adapter.geode.util.GeodeUtils.createClientCache;
-import static org.apache.calcite.adapter.geode.util.GeodeUtils.createRelDataType;
/**
* Schema mapped onto a Geode Region.
*/
public class GeodeSchema extends AbstractSchema {
- protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();
-
- final ClientCache clientCache;
- private final SchemaPlus parentSchema;
- private String[] regionNames;
+ final GemFireCache cache;
+ private final List<String> regionNames;
private ImmutableMap<String, Table> tableMap;
- public GeodeSchema(String locatorHost, int locatorPort,
- String[] regionNames, String pdxAutoSerializerPackageExp,
- SchemaPlus parentSchema) {
- super();
- this.regionNames = regionNames;
- this.parentSchema = parentSchema;
+ GeodeSchema(String locatorHost, int locatorPort,
+ Iterable<String> regionNames, String pdxAutoSerializerPackageExp) {
+ this(createClientCache(locatorHost, locatorPort, pdxAutoSerializerPackageExp, true),
+ regionNames);
+ }
- this.clientCache = createClientCache(locatorHost, locatorPort,
- pdxAutoSerializerPackageExp, true);
+ GeodeSchema(final GemFireCache cache, final Iterable<String> regionNames) {
+ super();
+ this.cache = Objects.requireNonNull(cache, "clientCache");
+ this.regionNames = ImmutableList.copyOf(Objects.requireNonNull(regionNames, "regionNames"));
}
@Override protected Map<String, Table> getTableMap() {
@@ -64,17 +59,9 @@ public class GeodeSchema extends AbstractSchema {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
- // Extract the first entity of each Regions and use it to build a table types
for (String regionName : regionNames) {
- Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
-
- Iterator regionIterator = region.keySetOnServer().iterator();
-
- Object firstRegionEntry = region.get(regionIterator.next());
- // TODO: how to handle empty Regions? JMX?
- Table table = new GeodeTable(this, regionName, createRelDataType(firstRegionEntry),
- clientCache);
-
+ Region region = GeodeUtils.createRegion(cache, regionName);
+ Table table = new GeodeTable(region);
builder.put(regionName, table);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java
index 0348a0d..e436ff1 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java
@@ -24,6 +24,7 @@ import org.apache.calcite.schema.SchemaPlus;
import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
import java.util.Map;
/**
@@ -61,8 +62,8 @@ public class GeodeSchemaFactory implements SchemaFactory {
GeoFunctions.class.getName(), "*", true);
}
- return new GeodeSchema(locatorHost, locatorPort, regionNames,
- pbxSerializablePackagePath, parentSchema);
+ return new GeodeSchema(locatorHost, locatorPort, Arrays.asList(regionNames),
+ pbxSerializablePackagePath);
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java
index 02e7b72..cebe5f7 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSort.java
@@ -42,7 +42,7 @@ public class GeodeSort extends Sort implements GeodeRel {
public static final String DESC = "DESC";
/** Creates a GeodeSort. */
- public GeodeSort(RelOptCluster cluster, RelTraitSet traitSet,
+ GeodeSort(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, RelCollation collation, RexNode fetch) {
super(cluster, traitSet, input, collation, null, fetch);
@@ -68,9 +68,7 @@ public class GeodeSort extends Sort implements GeodeRel {
}
@Override public void implement(GeodeImplementContext geodeImplementContext) {
-
- ((GeodeRel) getInput()).implement(geodeImplementContext);
-
+ geodeImplementContext.visitChild(getInput());
List<RelFieldCollation> sortCollations = collation.getFieldCollations();
@@ -85,9 +83,8 @@ public class GeodeSort extends Sort implements GeodeRel {
geodeImplementContext.addOrderByFields(orderByFields);
}
-
if (fetch != null) {
- geodeImplementContext.setLimit(((RexLiteral) fetch).getValue().toString());
+ geodeImplementContext.setLimit(((RexLiteral) fetch).getValueAs(Long.class));
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTable.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTable.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTable.java
index c39b94c..342effc 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTable.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTable.java
@@ -16,6 +16,7 @@
*/
package org.apache.calcite.adapter.geode.rel;
+import org.apache.calcite.adapter.geode.util.GeodeUtils;
import org.apache.calcite.adapter.geode.util.JavaTypeFactoryExtImpl;
import org.apache.calcite.adapter.java.AbstractQueryableTable;
import org.apache.calcite.linq4j.AbstractEnumerable;
@@ -30,13 +31,15 @@ import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeImpl;
import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.runtime.Hook;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.schema.impl.AbstractTableQueryable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.Util;
-import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.GemFireCache;
+import org.apache.geode.cache.Region;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.SelectResults;
@@ -48,6 +51,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
/**
@@ -55,25 +59,15 @@ import java.util.Map;
*/
public class GeodeTable extends AbstractQueryableTable implements TranslatableTable {
- protected static final Logger LOGGER = LoggerFactory.getLogger(GeodeTable.class.getName());
+ private static final Logger LOGGER = LoggerFactory.getLogger(GeodeTable.class.getName());
- private GeodeSchema schema;
+ private final String regionName;
+ private final RelDataType rowType;
- private String regionName;
-
- private RelDataType relDataType;
-
- private ClientCache clientCache;
-
- public GeodeTable(GeodeSchema schema,
- String regionName,
- RelDataType relDataType,
- ClientCache clientCache) {
+ GeodeTable(Region<?, ?> region) {
super(Object[].class);
- this.schema = schema;
- this.regionName = regionName;
- this.relDataType = relDataType;
- this.clientCache = clientCache;
+ this.regionName = region.getName();
+ this.rowType = GeodeUtils.autodetectRelTypeFromRegion(region);
}
public String toString() {
@@ -91,14 +85,14 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
* @param predicates A list of predicates which should be used in the query
* @return Enumerator of results
*/
- public Enumerable<Object> query(final ClientCache clientCache,
+ public Enumerable<Object> query(final GemFireCache clientCache,
final List<Map.Entry<String, Class>> fields,
final List<Map.Entry<String, String>> selectFields,
final List<Map.Entry<String, String>> aggregateFunctions,
final List<String> groupByFields,
List<String> predicates,
List<String> orderByFields,
- String limit) {
+ Long limit) {
final RelDataTypeFactory typeFactory = new JavaTypeFactoryExtImpl();
final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
@@ -122,9 +116,11 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
// Construct the list of fields to project
Builder<String> selectBuilder = ImmutableList.builder();
if (!groupByFields.isEmpty()) {
+ // manually add GROUP BY to select clause (GeodeProjection was not visited)
for (String groupByField : groupByFields) {
selectBuilder.add(groupByField + " AS " + groupByField);
}
+
if (!aggFuncMap.isEmpty()) {
for (Map.Entry<String, String> e : aggFuncMap.entrySet()) {
selectBuilder.add(e.getValue() + " AS " + e.getKey());
@@ -140,13 +136,19 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
selectBuilder.add("*");
}
} else {
- for (Map.Entry<String, String> field : selectFields) {
- selectBuilder.add(field.getKey() + " AS " + field.getValue());
+ if (!aggFuncMap.isEmpty()) {
+ for (Map.Entry<String, String> e : aggFuncMap.entrySet()) {
+ selectBuilder.add(e.getValue() + " AS " + e.getKey());
+ }
+ } else {
+ for (Map.Entry<String, String> field : selectFields) {
+ selectBuilder.add(field.getKey() + " AS " + field.getValue());
+ }
}
}
}
- final String oqlSelectStatement = Util.toString(selectBuilder.build(), " ", ", ", "");
+ final String oqlSelectStatement = Util.toString(selectBuilder.build(), "", ", ", "");
// Combine all predicates conjunctively
String whereClause = "";
@@ -174,20 +176,20 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
final String oqlQuery = queryBuilder.toString();
+ Hook.QUERY_PLAN.run(oqlQuery);
LOGGER.info("OQL: " + oqlQuery);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
- SelectResults results = null;
- QueryService queryService = clientCache.getQueryService();
-
+ final QueryService queryService = clientCache.getQueryService();
try {
- results = (SelectResults) queryService.newQuery(oqlQuery).execute();
+ SelectResults results = (SelectResults) queryService.newQuery(oqlQuery).execute();
+ return new GeodeEnumerator(results, resultRowType);
} catch (Exception e) {
- e.printStackTrace();
+ String message = String.format(Locale.ROOT, "Failed to execute query [%s] on %s",
+ oqlQuery, clientCache.getName());
+ throw new RuntimeException(message, e);
}
-
- return new GeodeEnumerator(results, resultRowType);
}
};
}
@@ -207,7 +209,7 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
}
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
- return relDataType;
+ return rowType;
}
/**
@@ -231,8 +233,8 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
return (GeodeTable) table;
}
- private ClientCache getClientCache() {
- return schema.unwrap(GeodeSchema.class).clientCache;
+ private GemFireCache getClientCache() {
+ return schema.unwrap(GeodeSchema.class).cache;
}
/**
@@ -246,7 +248,7 @@ public class GeodeTable extends AbstractQueryableTable implements TranslatableTa
List<String> groupByFields,
List<String> predicates,
List<String> order,
- String limit) {
+ Long limit) {
return getTable().query(getClientCache(), fields, selectFields,
aggregateFunctions, groupByFields, predicates, order, limit);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTableScan.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTableScan.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTableScan.java
index b83838f..766902d 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTableScan.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeTableScan.java
@@ -44,7 +44,7 @@ public class GeodeTableScan extends TableScan implements GeodeRel {
* @param geodeTable Geode table
* @param projectRowType Fields and types to project; null to project raw row
*/
- protected GeodeTableScan(RelOptCluster cluster, RelTraitSet traitSet,
+ GeodeTableScan(RelOptCluster cluster, RelTraitSet traitSet,
RelOptTable table, GeodeTable geodeTable, RelDataType projectRowType) {
super(cluster, traitSet, table);
this.geodeTable = geodeTable;
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeToEnumerableConverter.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeToEnumerableConverter.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeToEnumerableConverter.java
index 4b44573..1ba3ff7 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeToEnumerableConverter.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeToEnumerableConverter.java
@@ -35,7 +35,7 @@ import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterImpl;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
-import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.Pair;
@@ -76,7 +76,7 @@ public class GeodeToEnumerableConverter extends ConverterImpl implements Enumera
private static final Method GEODE_QUERY_METHOD =
Types.lookupMethod(GeodeTable.GeodeQueryable.class, "query", List.class,
List.class, List.class, List.class, List.class, List.class,
- String.class);
+ Long.class);
/**
* {@inheritDoc}
@@ -89,6 +89,8 @@ public class GeodeToEnumerableConverter extends ConverterImpl implements Enumera
final GeodeImplementContext geodeImplementContext = new GeodeImplementContext();
((GeodeRel) getInput()).implement(geodeImplementContext);
+ final RelDataType rowType = getRowType();
+
// PhysType is Enumerable Adapter class that maps SQL types (getRowType)
// with physical Java types (getJavaTypes())
final PhysType physType = PhysTypeImpl.of(
@@ -112,10 +114,11 @@ public class GeodeToEnumerableConverter extends ConverterImpl implements Enumera
Expressions.call(
geodeImplementContext.table.getExpression(GeodeTable.GeodeQueryable.class),
GEODE_QUERY_METHOD,
+ // fields
constantArrayList(Pair.zip(geodeFieldNames(rowType), physFieldClasses), Pair.class),
- // physical fields
- constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class),
// selected fields
+ constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class),
+ // aggregate functions
constantArrayList(
toListMapPairs(geodeImplementContext.oqlAggregateFunctions), Pair.class),
constantArrayList(geodeImplementContext.groupByFields, String.class),
@@ -123,8 +126,6 @@ public class GeodeToEnumerableConverter extends ConverterImpl implements Enumera
constantArrayList(geodeImplementContext.orderByFields, String.class),
Expressions.constant(geodeImplementContext.limitValue)));
- Hook.QUERY_PLAN.run(geodeImplementContext);
-
return implementor.result(physType, blockBuilder.toBlock());
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/simple/GeodeSimpleSchema.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/simple/GeodeSimpleSchema.java b/geode/src/main/java/org/apache/calcite/adapter/geode/simple/GeodeSimpleSchema.java
index bb98e60..14f2b8c 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/simple/GeodeSimpleSchema.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/simple/GeodeSimpleSchema.java
@@ -27,7 +27,7 @@ import com.google.common.collect.ImmutableMap;
import java.util.Map;
-import static org.apache.calcite.adapter.geode.util.GeodeUtils.createRelDataType;
+import static org.apache.calcite.adapter.geode.util.GeodeUtils.autodetectRelTypeFromRegion;
/**
* Geode Simple Schema.
@@ -64,12 +64,9 @@ public class GeodeSimpleSchema extends AbstractSchema {
for (String regionName : regionNames) {
- Region region = GeodeUtils.createRegionProxy(clientCache, regionName);
+ Region region = GeodeUtils.createRegion(clientCache, regionName);
- // TODO: What if the region is empty
- Object regionEntry = region.get(region.keySetOnServer().iterator().next());
-
- Table table = new GeodeSimpleScannableTable(regionName, createRelDataType(regionEntry),
+ Table table = new GeodeSimpleScannableTable(regionName, autodetectRelTypeFromRegion(region),
clientCache);
builder.put(regionName, table);
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/main/java/org/apache/calcite/adapter/geode/util/GeodeUtils.java
----------------------------------------------------------------------
diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/util/GeodeUtils.java b/geode/src/main/java/org/apache/calcite/adapter/geode/util/GeodeUtils.java
index 9f1648f..e49be07 100644
--- a/geode/src/main/java/org/apache/calcite/adapter/geode/util/GeodeUtils.java
+++ b/geode/src/main/java/org/apache/calcite/adapter/geode/util/GeodeUtils.java
@@ -24,6 +24,7 @@ import org.apache.calcite.util.Util;
import org.apache.commons.lang3.StringUtils;
import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
@@ -38,8 +39,11 @@ import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -114,19 +118,27 @@ public class GeodeUtils {
/**
* Obtains a proxy pointing to an existing Region on the server
*
- * @param clientCache {@link ClientCache} instance to interact with the Geode server
+ * @param cache {@link GemFireCache} instance to interact with the Geode server
* @param regionName Name of the region to create proxy for.
* @return Returns a Region proxy to a remote (on the Server) regions.
*/
- public static synchronized Region createRegionProxy(ClientCache clientCache,
- String regionName) {
+ public static synchronized Region createRegion(GemFireCache cache, String regionName) {
+ Objects.requireNonNull(cache, "cache");
+ Objects.requireNonNull(regionName, "regionName");
Region region = REGION_MAP.get(regionName);
if (region == null) {
- region = clientCache
- .createClientRegionFactory(ClientRegionShortcut.PROXY)
- .create(regionName);
+ try {
+ region = ((ClientCache) cache)
+ .createClientRegionFactory(ClientRegionShortcut.PROXY)
+ .create(regionName);
+ } catch (IllegalStateException e) {
+ // means this is a server cache (probably part of embedded testing)
+ region = cache.getRegion(regionName);
+ }
+
REGION_MAP.put(regionName, region);
}
+
return region;
}
@@ -262,8 +274,42 @@ public class GeodeUtils {
return o;
}
+ /**
+ * Extract the first entity of each Regions and use it to build a table types.
+ *
+ * @param region existing region
+ * @return derived data type.
+ */
+ public static RelDataType autodetectRelTypeFromRegion(Region<?, ?> region) {
+ Objects.requireNonNull(region, "region");
+
+ // try to detect type using value constraints (if they exists)
+ final Class<?> constraint = region.getAttributes().getValueConstraint();
+ if (constraint != null && !PdxInstance.class.isAssignableFrom(constraint)) {
+ return new JavaTypeFactoryExtImpl().createStructType(constraint);
+ }
+
+ final Iterator<?> iter;
+ if (region.getAttributes().getPoolName() == null) {
+ // means current cache is server (not ClientCache)
+ iter = region.keySet().iterator();
+ } else {
+ // for ClientCache
+ iter = region.keySetOnServer().iterator();
+ }
+
+ if (!iter.hasNext()) {
+ String message = String.format(Locale.ROOT, "Region %s is empty, can't "
+ + "autodetect type(s)", region.getName());
+ throw new IllegalStateException(message);
+ }
+
+ final Object entry = region.get(iter.next());
+ return createRelDataType(entry);
+ }
+
// Create Relational Type by inferring a Geode entry or response instance.
- public static RelDataType createRelDataType(Object regionEntry) {
+ private static RelDataType createRelDataType(Object regionEntry) {
JavaTypeFactoryExtImpl typeFactory = new JavaTypeFactoryExtImpl();
if (regionEntry instanceof PdxInstance) {
return typeFactory.createPdxType((PdxInstance) regionEntry);
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/AbstractGeodeTest.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/AbstractGeodeTest.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/AbstractGeodeTest.java
new file mode 100644
index 0000000..3f7b7f2
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/AbstractGeodeTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.adapter.geode.rel;
+
+import org.junit.ClassRule;
+
+/**
+ * Base class which allows sharing same geode instance across all tests. Also due to legacy
+ * reasons there can't be more than one Geode instance (running in parallel) for a single JVM.
+ */
+public abstract class AbstractGeodeTest {
+
+ @ClassRule
+ public static final GeodeEmbeddedPolicy POLICY = GeodeEmbeddedPolicy.create().share();
+
+}
+
+// End AbstractGeodeTest.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/BaseGeodeAdapterIT.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/BaseGeodeAdapterIT.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/BaseGeodeAdapterIT.java
deleted file mode 100644
index 6c9c765..0000000
--- a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/BaseGeodeAdapterIT.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * 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.adapter.geode.rel;
-
-import org.apache.calcite.linq4j.function.Function1;
-import org.apache.calcite.util.Sources;
-
-import org.junit.Assert;
-
-import java.io.PrintStream;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Geode Adapter IT Test
- */
-public class BaseGeodeAdapterIT {
-
- /**
- * Returns a function that checks the contents of a result set against an
- * expected string.
- */
- private static Function1<ResultSet, Void> expect(final String... expected) {
- return resultSet -> {
- try {
- final List<String> lines = new ArrayList<>();
- BaseGeodeAdapterIT.collect(lines, resultSet);
- Assert.assertEquals(Arrays.asList(expected), lines);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- return null;
- };
- }
-
- private static void collect(List<String> result, ResultSet resultSet)
- throws SQLException {
- final StringBuilder buf = new StringBuilder();
- while (resultSet.next()) {
- buf.setLength(0);
- int n = resultSet.getMetaData().getColumnCount();
- String sep = "";
- for (int i = 1; i <= n; i++) {
- buf.append(sep)
- .append(resultSet.getMetaData().getColumnLabel(i))
- .append("=")
- .append(resultSet.getString(i));
- sep = "; ";
- }
- result.add(toLinux(buf.toString()));
- }
- }
-
- public static String toLinux(String s) {
- return s.replaceAll("\r\n", "\n");
- }
-
- protected void checkSql(String model, String sql) throws SQLException {
- checkSql(sql, model, output());
- }
-
- protected Function1<ResultSet, Void> output() {
- return resultSet -> {
- try {
- output(resultSet, System.out);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- return null;
- };
- }
-
- protected void checkSql(String model, String sql, final String... expected)
- throws SQLException {
- checkSql(sql, model, expect(expected));
- }
-
- protected void checkSql(String sql, String model, Function1<ResultSet, Void> fn)
- throws SQLException {
- Connection connection = null;
- Statement statement = null;
- try {
- Properties info = new Properties();
- info.put("model", jsonPath(model));
- connection = DriverManager.getConnection("jdbc:calcite:", info);
- statement = connection.createStatement();
- final ResultSet resultSet = statement.executeQuery(sql);
- fn.apply(resultSet);
- } finally {
- close(connection, statement);
- }
- }
-
- private String jsonPath(String model) {
- return resourcePath(model + ".json");
- }
-
- private String resourcePath(String path) {
- return Sources.of(GeodeAdapterIT.class.getResource("/" + path)).file().getAbsolutePath();
- }
-
- private void output(ResultSet resultSet, PrintStream out)
- throws SQLException {
- final ResultSetMetaData metaData = resultSet.getMetaData();
- final int columnCount = metaData.getColumnCount();
- while (resultSet.next()) {
- for (int i = 1; true; i++) {
- out.print(resultSet.getString(i));
- if (i < columnCount) {
- out.print(", ");
- } else {
- out.println();
- break;
- }
- }
- }
- }
-
- private void close(Connection connection, Statement statement) {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException e) {
- // ignore
- }
- }
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- // ignore
- }
- }
- }
-}
-
-// End BaseGeodeAdapterIT.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterBookshopIT.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterBookshopIT.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterBookshopIT.java
deleted file mode 100644
index cd38841..0000000
--- a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterBookshopIT.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * 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.adapter.geode.rel;
-
-import org.apache.calcite.test.CalciteAssert;
-import org.apache.calcite.util.Sources;
-import org.apache.calcite.util.Util;
-
-import com.google.common.collect.ImmutableMap;
-
-import org.junit.Test;
-
-/**
- * Tests for the {@code org.apache.calcite.adapter.geode} package.
- *
- * <p>Before calling this rel, you need to populate Geode, as follows:
- *
- * <blockquote><code>
- * git clone https://github.com/vlsi/calcite-test-dataset<br>
- * cd calcite-rel-dataset<br>
- * mvn install
- * </code></blockquote>
- *
- * <p>This will create a virtual machine with Geode and the "bookshop"
- * and "zips" rel dataset.
- */
-public class GeodeAdapterBookshopIT {
- /**
- * Connection factory based on the "geode relational " model.
- */
- public static final ImmutableMap<String, String> GEODE =
- ImmutableMap.of("model",
- Sources.of(GeodeAdapterBookshopIT.class.getResource("/model-bookshop.json"))
- .file().getAbsolutePath());
-
-
- /**
- * Whether to run Geode tests. Enabled by default, however rel is only
- * included if "it" profile is activated ({@code -Pit}). To disable,
- * specify {@code -Dcalcite.rel.geode=false} on the Java command line.
- */
- public static final boolean ENABLED = Util.getBooleanProperty("calcite.rel.geode", true);
-
- /**
- * Whether to run this rel.
- */
- protected boolean enabled() {
- return ENABLED;
- }
-
- @Test
- public void testSelect() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select * from \"BookMaster\"")
- .returnsCount(3);
- }
-
- @Test
- public void testWhereEqual() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select * from \"BookMaster\" WHERE \"itemNumber\" = 123")
- .returnsCount(1)
- .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane;"
- + " retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
- + "Treatises\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeFilter(condition=[=(CAST($0):INTEGER, 123)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- @Test
- public void testWhereWithAnd() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select * from \"BookMaster\" WHERE \"itemNumber\" > 122 "
- + "AND \"itemNumber\" <= 123")
- .returnsCount(1)
- .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane; "
- + "retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
- + "Treatises\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeFilter(condition=[AND(>($0, 122), <=($0, 123))])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- @Test
- public void testWhereWithOr() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"author\" from \"BookMaster\" "
- + "WHERE \"itemNumber\" = 123 OR \"itemNumber\" = 789")
- .returnsCount(2)
- .returnsUnordered("author=Jim Heavisides", "author=Daisy Mae West")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(author=[$4])\n"
- + " GeodeFilter(condition=[OR(=(CAST($0):INTEGER, 123), "
- + "=(CAST($0):INTEGER, 789))])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testWhereWithAndOr() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("SELECT \"author\" from \"BookMaster\" "
- + "WHERE (\"itemNumber\" > 123 AND \"itemNumber\" = 789) "
- + "OR \"author\"='Daisy Mae West'")
- .returnsCount(2)
- .returnsUnordered("author=Jim Heavisides", "author=Daisy Mae West")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(author=[$4])\n"
- + " GeodeFilter(condition=[OR(AND(>($0, 123), =(CAST($0):INTEGER, 789)), "
- + "=(CAST($4):VARCHAR CHARACTER SET \"ISO-8859-1\" "
- + "COLLATE \"ISO-8859-1$en_US$primary\", 'Daisy Mae West'))])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n"
- + "\n");
- }
-
- // TODO: Not supported YET
- @Test
- public void testWhereWithOrAnd() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("SELECT \"author\" from \"BookMaster\" "
- + "WHERE (\"itemNumber\" > 100 OR \"itemNumber\" = 789) "
- + "AND \"author\"='Daisy Mae West'")
- .returnsCount(1)
- .returnsUnordered("author=Daisy Mae West")
- .explainContains("");
- }
-
- @Test
- public void testProjectionsAndWhereGreatThan() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"author\" from \"BookMaster\" WHERE \"itemNumber\" > 123")
- .returnsCount(2)
- .returns("author=Clarence Meeks\n"
- + "author=Jim Heavisides\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(author=[$4])\n"
- + " GeodeFilter(condition=[>($0, 123)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- @Test
- public void testLimit() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select * from \"BookMaster\" LIMIT 1")
- .returnsCount(1)
- .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane; "
- + "retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
- + "Treatises\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeSort(fetch=[1])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- @Test
- public void testSortWithProjection() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\" from \"BookMaster\" ORDER BY \"yearPublished\" ASC")
- .returnsCount(3)
- .returns("yearPublished=1971\n"
- + "yearPublished=2011\n"
- + "yearPublished=2011\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeSort(sort0=[$0], dir0=[ASC])\n"
- + " GeodeProject(yearPublished=[$3])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testSortWithProjectionAndLimit() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\" from \"BookMaster\" ORDER BY \"yearPublished\" "
- + "LIMIT 2")
- .returnsCount(2)
- .returns("yearPublished=1971\n"
- + "yearPublished=2011\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(yearPublished=[$3])\n"
- + " GeodeSort(sort0=[$3], dir0=[ASC], fetch=[2])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testSortBy2Columns() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\", \"itemNumber\" from \"BookMaster\" ORDER BY "
- + "\"yearPublished\" ASC, \"itemNumber\" DESC")
- .returnsCount(3)
- .returns("yearPublished=1971; itemNumber=456\n"
- + "yearPublished=2011; itemNumber=789\n"
- + "yearPublished=2011; itemNumber=123\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(yearPublished=[$3], itemNumber=[$0])\n"
- + " GeodeSort(sort0=[$3], sort1=[$0], dir0=[ASC], dir1=[DESC])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- //
- // TEST Group By and Aggregation Function Support
- //
-
- /**
- * OQL Error: Query contains group by columns not present in projected fields
- * Solution: Automatically expand the projections to include all missing GROUP By columns.
- */
- @Test
- public void testAddMissingGroupByColumnToProjectedFields() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\" from \"BookMaster\" GROUP BY \"yearPublished\", "
- + "\"author\"")
- .returnsCount(3)
- .returns("yearPublished=1971\n"
- + "yearPublished=2011\n"
- + "yearPublished=2011\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(yearPublished=[$0])\n"
- + " GeodeAggregate(group=[{3, 4}])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- /**
- * When the group by columns match the projected fields, the optimizers removes the projected
- * relation.
- */
- @Test
- public void testMissingProjectRelationOnGroupByColumnMatchingProjectedFields() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\" from \"BookMaster\" GROUP BY \"yearPublished\"")
- .returnsCount(2)
- .returns("yearPublished=1971\n"
- + "yearPublished=2011\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{3}])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- /**
- * When the group by columns match the projected fields, the optimizers removes the projected
- * relation.
- */
- @Test
- public void testMissingProjectRelationOnGroupByColumnMatchingProjectedFields2() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\", MAX(\"retailCost\") from \"BookMaster\" GROUP BY "
- + "\"yearPublished\"")
- .returnsCount(2)
- .returns("yearPublished=1971; EXPR$1=11.99\n"
- + "yearPublished=2011; EXPR$1=59.99\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{3}], EXPR$1=[MAX($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])");
- }
-
- @Test
- public void testCount() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select COUNT(\"retailCost\") from \"BookMaster\"")
- .returnsCount(1)
- .returns("EXPR$0=3\n")
- .returnsValue("3")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{}], EXPR$0=[COUNT($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testCountStar() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select COUNT(*) from \"BookMaster\"")
- .returnsCount(1)
- .returns("EXPR$0=3\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{}], EXPR$0=[COUNT()])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testCountInGroupBy() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\", COUNT(\"retailCost\") from \"BookMaster\" GROUP BY "
- + "\"yearPublished\"")
- .returnsCount(2)
- .returns("yearPublished=1971; EXPR$1=1\n"
- + "yearPublished=2011; EXPR$1=2\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{3}], EXPR$1=[COUNT($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testMaxMinSumAvg() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select MAX(\"retailCost\"), MIN(\"retailCost\"), SUM(\"retailCost\"), AVG"
- + "(\"retailCost\") from \"BookMaster\"")
- .returnsCount(1)
- .returns("EXPR$0=59.99; EXPR$1=11.99; EXPR$2=106.97000122070312; "
- + "EXPR$3=35.65666580200195\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{}], EXPR$0=[MAX($2)], EXPR$1=[MIN($2)], EXPR$2=[SUM($2)"
- + "], EXPR$3=[AVG($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testMaxMinSumAvgInGroupBy() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\", MAX(\"retailCost\"), MIN(\"retailCost\"), SUM"
- + "(\"retailCost\"), AVG(\"retailCost\") from \"BookMaster\" "
- + "GROUP BY \"yearPublished\"")
- .returnsCount(2)
- .returns("yearPublished=2011; EXPR$1=59.99; EXPR$2=34.99; EXPR$3=94.9800033569336; "
- + "EXPR$4=47.4900016784668\n"
- + "yearPublished=1971; EXPR$1=11.99; EXPR$2=11.99; EXPR$3=11.989999771118164; "
- + "EXPR$4=11.989999771118164\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeAggregate(group=[{3}], EXPR$1=[MAX($2)], EXPR$2=[MIN($2)], EXPR$3=[SUM($2)"
- + "], EXPR$4=[AVG($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testGroupBy() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"yearPublished\", MAX(\"retailCost\") AS MAXCOST, \"author\" from "
- + "\"BookMaster\" GROUP BY \"yearPublished\", \"author\"")
- .returnsCount(3)
- .returns("yearPublished=2011; MAXCOST=59.99; author=Jim Heavisides\n"
- + "yearPublished=1971; MAXCOST=11.99; author=Clarence Meeks\n"
- + "yearPublished=2011; MAXCOST=34.99; author=Daisy Mae West\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(yearPublished=[$0], MAXCOST=[$2], author=[$1])\n"
- + " GeodeAggregate(group=[{3, 4}], MAXCOST=[MAX($2)])\n"
- + " GeodeTableScan(table=[[TEST, BookMaster]])\n");
- }
-
- @Test
- public void testSelectWithNestedPdx() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select * from \"BookCustomer\" limit 2")
- .returnsCount(2)
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeSort(fetch=[2])\n"
- + " GeodeTableScan(table=[[TEST, BookCustomer]])\n");
- }
-
- @Test
- public void testSelectWithNestedPdx2() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"primaryAddress\" from \"BookCustomer\" limit 2")
- .returnsCount(2)
- .returns("primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,"
- + "postalCode,country,phoneNumber,addressTag]\n"
- + "primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,postalCode,"
- + "country,phoneNumber,addressTag]\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(primaryAddress=[$3])\n"
- + " GeodeSort(fetch=[2])\n"
- + " GeodeTableScan(table=[[TEST, BookCustomer]])\n");
- }
-
- @Test
- public void testSelectWithNestedPdxFieldAccess() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"primaryAddress\"['city'] as \"city\" from \"BookCustomer\" limit 2")
- .returnsCount(2)
- .returns("city=Topeka\n"
- + "city=San Francisco\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(city=[ITEM($3, 'city')])\n"
- + " GeodeSort(fetch=[2])\n"
- + " GeodeTableScan(table=[[TEST, BookCustomer]])\n");
- }
-
- @Test
- public void testSelectWithNullFieldValue() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("select \"primaryAddress\"['addressLine2'] from \"BookCustomer\" limit"
- + " 2")
- .returnsCount(2)
- .returns("EXPR$0=null\n"
- + "EXPR$0=null\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(EXPR$0=[ITEM($3, 'addressLine2')])\n"
- + " GeodeSort(fetch=[2])\n"
- + " GeodeTableScan(table=[[TEST, BookCustomer]])\n");
- }
-
- @Test
- public void testFilterWithNestedField() {
- CalciteAssert.that()
- .enable(enabled())
- .with(GEODE)
- .query("SELECT \"primaryAddress\"['postalCode'] AS \"postalCode\"\n"
- + "FROM \"TEST\".\"BookCustomer\"\n"
- + "WHERE \"primaryAddress\"['postalCode'] > '0'\n")
- .returnsCount(3)
- .returns("postalCode=50505\n"
- + "postalCode=50505\n"
- + "postalCode=50505\n")
- .explainContains("PLAN=GeodeToEnumerableConverter\n"
- + " GeodeProject(postalCode=[ITEM($3, 'postalCode')])\n"
- + " GeodeFilter(condition=[>(ITEM($3, 'postalCode'), '0')])\n"
- + " GeodeTableScan(table=[[TEST, BookCustomer]])\n");
- }
-
-}
-
-// End GeodeAdapterBookshopIT.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterIT.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterIT.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterIT.java
deleted file mode 100644
index f416d5e..0000000
--- a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAdapterIT.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.adapter.geode.rel;
-
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-/**
- * Tests for the {@code org.apache.calcite.adapter.geode} package.
- *
- * <p>Before calling this rel, you need to populate Geode, as follows:
- *
- * <blockquote><code>
- * git clone https://github.com/vlsi/calcite-test-dataset<br>
- * cd calcite-rel-dataset<br>
- * mvn install
- * </code></blockquote>
- *
- * <p>This will create a virtual machine with Geode and the "bookshop" and "zips" rel dataset.
- */
-public class GeodeAdapterIT extends BaseGeodeAdapterIT {
-
- @Test
- public void testSqlSimple() throws SQLException {
- checkSql("model-bookshop", "SELECT \"itemNumber\" "
- + "FROM \"BookMaster\" WHERE \"itemNumber\" > 123");
- }
-
- @Test
- public void testSqlSingleNumberWhereFilter() throws SQLException {
- checkSql("model-bookshop", "SELECT * FROM \"BookMaster\" "
- + "WHERE \"itemNumber\" = 123");
- }
-
- @Test
- public void testSqlDistinctSort() throws SQLException {
- checkSql("model-bookshop", "SELECT DISTINCT \"itemNumber\", \"author\" "
- + "FROM \"BookMaster\" ORDER BY \"itemNumber\", \"author\"");
- }
-
- @Test
- public void testSqlDistinctSort2() throws SQLException {
- checkSql("model-bookshop", "SELECT \"itemNumber\", \"author\" "
- + "FROM \"BookMaster\" GROUP BY \"itemNumber\", \"author\" ORDER BY \"itemNumber\", "
- + "\"author\"");
- }
-
- @Test
- public void testSqlDistinctSort3() throws SQLException {
- checkSql("model-bookshop", "SELECT DISTINCT * FROM \"BookMaster\"");
- }
-
-
- @Test
- public void testSqlLimit2() throws SQLException {
- checkSql("model-bookshop", "SELECT DISTINCT * FROM \"BookMaster\" LIMIT 2");
- }
-
-
- @Test
- public void testSqlDisjunciton() throws SQLException {
- checkSql("model-bookshop", "SELECT \"author\" FROM \"BookMaster\" "
- + "WHERE \"itemNumber\" = 789 OR \"itemNumber\" = 123");
- }
-
- @Test
- public void testSqlConjunciton() throws SQLException {
- checkSql("model-bookshop", "SELECT \"author\" FROM \"BookMaster\" "
- + "WHERE \"itemNumber\" = 789 AND \"author\" = 'Jim Heavisides'");
- }
-
- @Test
- public void testSqlBookMasterWhere() throws SQLException {
- checkSql("model-bookshop", "select \"author\", \"title\" from \"BookMaster\" "
- + "WHERE \"author\" = \'Jim Heavisides\' LIMIT 2");
- }
-
- @Test
- public void testSqlBookMasterCount() throws SQLException {
- checkSql("model-bookshop", "select count(*) from \"BookMaster\"");
- }
-}
-
-// End GeodeAdapterIT.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAssertions.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAssertions.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAssertions.java
new file mode 100644
index 0000000..037f7ba
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeAssertions.java
@@ -0,0 +1,44 @@
+/*
+ * 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.adapter.geode.rel;
+
+import java.util.List;
+import java.util.function.Consumer;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Various validations for geode tests.
+ */
+class GeodeAssertions {
+
+ private GeodeAssertions() {}
+
+ static Consumer<List> query(final String query) {
+ return actual -> {
+ String actualString =
+ actual == null || actual.isEmpty()
+ ? null
+ : ((String) actual.get(0));
+
+ assertEquals(query, actualString);
+ };
+ }
+
+}
+
+// End GeodeAssertions.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/ed424ed8/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeBookstoreTest.java
----------------------------------------------------------------------
diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeBookstoreTest.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeBookstoreTest.java
new file mode 100644
index 0000000..12cc34e
--- /dev/null
+++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeBookstoreTest.java
@@ -0,0 +1,483 @@
+/*
+ * 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.adapter.geode.rel;
+
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.test.CalciteAssert;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+/**
+ * Tests using {@code Bookshop} schema.
+ */
+public class GeodeBookstoreTest extends AbstractGeodeTest {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ Cache cache = POLICY.cache();
+ Region<?, ?> bookMaster = cache.<String, Object>createRegionFactory().create("BookMaster");
+ new JsonLoader(bookMaster).loadClasspathResource("/book_master.json");
+
+ Region<?, ?> bookCustomer = cache.<String, Object>createRegionFactory().create("BookCustomer");
+ new JsonLoader(bookCustomer).loadClasspathResource("/book_customer.json");
+
+ }
+
+ private CalciteAssert.ConnectionFactory newConnectionFactory() {
+ return new CalciteAssert.ConnectionFactory() {
+ @Override public Connection createConnection() throws SQLException {
+ final Connection connection = DriverManager.getConnection("jdbc:calcite:lex=JAVA");
+ final SchemaPlus root = connection.unwrap(CalciteConnection.class).getRootSchema();
+ root.add("geode",
+ new GeodeSchema(POLICY.cache(), Arrays.asList("BookMaster", "BookCustomer")));
+ return connection;
+ }
+ };
+ }
+
+ private CalciteAssert.AssertThat calciteAssert() {
+ return CalciteAssert.that()
+ .with(newConnectionFactory());
+ }
+
+ @Test
+ public void testSelect() {
+ calciteAssert()
+ .query("select * from geode.BookMaster")
+ .returnsCount(3);
+ }
+
+ @Test
+ public void testWhereEqual() {
+ calciteAssert()
+ .query("select * from geode.BookMaster WHERE itemNumber = 123")
+ .returnsCount(1)
+ .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane;"
+ + " retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
+ + "Treatises\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeFilter(condition=[=(CAST($0):INTEGER, 123)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ @Test
+ public void testWhereWithAnd() {
+ calciteAssert()
+ .query("select * from geode.BookMaster WHERE itemNumber > 122 "
+ + "AND itemNumber <= 123")
+ .returnsCount(1)
+ .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane; "
+ + "retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
+ + "Treatises\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeFilter(condition=[AND(>($0, 122), <=($0, 123))])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ @Test
+ public void testWhereWithOr() {
+ calciteAssert()
+ .query("select author from geode.BookMaster "
+ + "WHERE itemNumber = 123 OR itemNumber = 789")
+ .returnsCount(2)
+ .returnsUnordered("author=Jim Heavisides", "author=Daisy Mae West")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(author=[$4])\n"
+ + " GeodeFilter(condition=[OR(=(CAST($0):INTEGER, 123), "
+ + "=(CAST($0):INTEGER, 789))])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testWhereWithAndOr() {
+ calciteAssert()
+ .query("SELECT author from geode.BookMaster "
+ + "WHERE (itemNumber > 123 AND itemNumber = 789) "
+ + "OR author='Daisy Mae West'")
+ .returnsCount(2)
+ .returnsUnordered("author=Jim Heavisides", "author=Daisy Mae West")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(author=[$4])\n"
+ + " GeodeFilter(condition=[OR(AND(>($0, 123), =(CAST($0):INTEGER, 789)), "
+ + "=(CAST($4):VARCHAR CHARACTER SET \"ISO-8859-1\" "
+ + "COLLATE \"ISO-8859-1$en_US$primary\", 'Daisy Mae West'))])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n"
+ + "\n");
+ }
+
+ // TODO: Not supported YET
+ @Test
+ public void testWhereWithOrAnd() {
+ calciteAssert()
+ .query("SELECT author from geode.BookMaster "
+ + "WHERE (itemNumber > 100 OR itemNumber = 789) "
+ + "AND author='Daisy Mae West'")
+ .returnsCount(1)
+ .returnsUnordered("author=Daisy Mae West")
+ .explainContains("");
+ }
+
+ @Test
+ public void testProjectionsAndWhereGreatThan() {
+ calciteAssert()
+ .query("select author from geode.BookMaster WHERE itemNumber > 123")
+ .returnsCount(2)
+ .returns("author=Clarence Meeks\n"
+ + "author=Jim Heavisides\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(author=[$4])\n"
+ + " GeodeFilter(condition=[>($0, 123)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ @Test
+ public void testLimit() {
+ calciteAssert()
+ .query("select * from geode.BookMaster LIMIT 1")
+ .returnsCount(1)
+ .returns("itemNumber=123; description=Run on sentences and drivel on all things mundane; "
+ + "retailCost=34.99; yearPublished=2011; author=Daisy Mae West; title=A Treatise of "
+ + "Treatises\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeSort(fetch=[1])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ @Test
+ public void testSortWithProjection() {
+ calciteAssert()
+ .query("select yearPublished from geode.BookMaster ORDER BY yearPublished ASC")
+ .returnsCount(3)
+ .returns("yearPublished=1971\n"
+ + "yearPublished=2011\n"
+ + "yearPublished=2011\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeSort(sort0=[$0], dir0=[ASC])\n"
+ + " GeodeProject(yearPublished=[$3])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testSortWithProjectionAndLimit() {
+ calciteAssert()
+ .query("select yearPublished from geode.BookMaster ORDER BY yearPublished "
+ + "LIMIT 2")
+ .returnsCount(2)
+ .returns("yearPublished=1971\n"
+ + "yearPublished=2011\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(yearPublished=[$3])\n"
+ + " GeodeSort(sort0=[$3], dir0=[ASC], fetch=[2])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testSortBy2Columns() {
+ calciteAssert()
+ .query("select yearPublished, itemNumber from geode.BookMaster ORDER BY "
+ + "yearPublished ASC, itemNumber DESC")
+ .returnsCount(3)
+ .returns("yearPublished=1971; itemNumber=456\n"
+ + "yearPublished=2011; itemNumber=789\n"
+ + "yearPublished=2011; itemNumber=123\n")
+ .queryContains(
+ GeodeAssertions.query("SELECT yearPublished AS yearPublished, "
+ + "itemNumber AS itemNumber "
+ + "FROM /BookMaster ORDER BY yearPublished ASC, itemNumber DESC"));
+ }
+
+ //
+ // geode Group By and Aggregation Function Support
+ //
+
+ /**
+ * OQL Error: Query contains group by columns not present in projected fields
+ * Solution: Automatically expand the projections to include all missing GROUP By columns.
+ */
+ @Test
+ public void testAddMissingGroupByColumnToProjectedFields() {
+ calciteAssert()
+ .query("select yearPublished from geode.BookMaster GROUP BY yearPublished, "
+ + "author")
+ .returnsCount(3)
+ .returns("yearPublished=1971\n"
+ + "yearPublished=2011\n"
+ + "yearPublished=2011\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(yearPublished=[$0])\n"
+ + " GeodeAggregate(group=[{3, 4}])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ /**
+ * When the group by columns match the projected fields, the optimizers removes the projected
+ * relation.
+ */
+ @Test
+ public void testMissingProjectRelationOnGroupByColumnMatchingProjectedFields() {
+ calciteAssert()
+ .query("select yearPublished from geode.BookMaster GROUP BY yearPublished")
+ .returnsCount(2)
+ .returns("yearPublished=1971\n"
+ + "yearPublished=2011\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{3}])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ /**
+ * When the group by columns match the projected fields, the optimizers removes the projected
+ * relation.
+ */
+ @Test
+ public void testMissingProjectRelationOnGroupByColumnMatchingProjectedFields2() {
+ calciteAssert()
+ .query("select yearPublished, MAX(retailCost) from geode.BookMaster GROUP BY "
+ + "yearPublished")
+ .returnsCount(2)
+ .returns("yearPublished=1971; EXPR$1=11.99\n"
+ + "yearPublished=2011; EXPR$1=59.99\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{3}], EXPR$1=[MAX($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])");
+ }
+
+ @Test
+ public void testCount() {
+ calciteAssert()
+ .query("select COUNT(retailCost) from geode.BookMaster")
+ .returnsCount(1)
+ .returns("EXPR$0=3\n")
+ .returnsValue("3")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{}], EXPR$0=[COUNT($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testCountStar() {
+ calciteAssert()
+ .query("select COUNT(*) from geode.BookMaster")
+ .returnsCount(1)
+ .returns("EXPR$0=3\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{}], EXPR$0=[COUNT()])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testCountInGroupBy() {
+ calciteAssert()
+ .query("select yearPublished, COUNT(retailCost) from geode.BookMaster GROUP BY "
+ + "yearPublished")
+ .returnsCount(2)
+ .returns("yearPublished=1971; EXPR$1=1\n"
+ + "yearPublished=2011; EXPR$1=2\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{3}], EXPR$1=[COUNT($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testMaxMinSumAvg() {
+ calciteAssert()
+ .query("select MAX(retailCost), MIN(retailCost), SUM(retailCost), AVG"
+ + "(retailCost) from geode.BookMaster")
+ .returnsCount(1)
+ .returns("EXPR$0=59.99; EXPR$1=11.99; EXPR$2=106.97000122070312; "
+ + "EXPR$3=35.65666580200195\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{}], EXPR$0=[MAX($2)], EXPR$1=[MIN($2)], EXPR$2=[SUM($2)"
+ + "], EXPR$3=[AVG($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testMaxMinSumAvgInGroupBy() {
+ calciteAssert()
+ .query("select yearPublished, MAX(retailCost), MIN(retailCost), SUM"
+ + "(retailCost), AVG(retailCost) from geode.BookMaster "
+ + "GROUP BY yearPublished")
+ .returnsCount(2)
+ .returns("yearPublished=2011; EXPR$1=59.99; EXPR$2=34.99; EXPR$3=94.9800033569336; "
+ + "EXPR$4=47.4900016784668\n"
+ + "yearPublished=1971; EXPR$1=11.99; EXPR$2=11.99; EXPR$3=11.989999771118164; "
+ + "EXPR$4=11.989999771118164\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeAggregate(group=[{3}], EXPR$1=[MAX($2)], EXPR$2=[MIN($2)], EXPR$3=[SUM($2)"
+ + "], EXPR$4=[AVG($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testGroupBy() {
+ calciteAssert()
+ .query("select yearPublished, MAX(retailCost) AS MAXCOST, author from "
+ + "geode.BookMaster GROUP BY yearPublished, author")
+ .returnsCount(3)
+ .returnsUnordered("yearPublished=2011; MAXCOST=59.99; author=Jim Heavisides",
+ "yearPublished=1971; MAXCOST=11.99; author=Clarence Meeks",
+ "yearPublished=2011; MAXCOST=34.99; author=Daisy Mae West")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(yearPublished=[$0], MAXCOST=[$2], author=[$1])\n"
+ + " GeodeAggregate(group=[{3, 4}], MAXCOST=[MAX($2)])\n"
+ + " GeodeTableScan(table=[[geode, BookMaster]])\n");
+ }
+
+ @Test
+ public void testSelectWithNestedPdx() {
+ calciteAssert()
+ .query("select * from geode.BookCustomer limit 2")
+ .returnsCount(2)
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeSort(fetch=[2])\n"
+ + " GeodeTableScan(table=[[geode, BookCustomer]])\n");
+ }
+
+ @Test
+ public void testSelectWithNestedPdx2() {
+ calciteAssert()
+ .query("select primaryAddress from geode.BookCustomer limit 2")
+ .returnsCount(2)
+ .returns("primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,"
+ + "postalCode,country,phoneNumber,addressTag]\n"
+ + "primaryAddress=PDX[addressLine1,addressLine2,addressLine3,city,state,postalCode,"
+ + "country,phoneNumber,addressTag]\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(primaryAddress=[$3])\n"
+ + " GeodeSort(fetch=[2])\n"
+ + " GeodeTableScan(table=[[geode, BookCustomer]])\n");
+ }
+
+ @Test
+ public void testSelectWithNestedPdxFieldAccess() {
+ calciteAssert()
+ .query("select primaryAddress['city'] as city from geode.BookCustomer limit 2")
+ .returnsCount(2)
+ .returns("city=Topeka\n"
+ + "city=San Francisco\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(city=[ITEM($3, 'city')])\n"
+ + " GeodeSort(fetch=[2])\n"
+ + " GeodeTableScan(table=[[geode, BookCustomer]])\n");
+ }
+
+ @Test
+ public void testSelectWithNullFieldValue() {
+ calciteAssert()
+ .query("select primaryAddress['addressLine2'] from geode.BookCustomer limit"
+ + " 2")
+ .returnsCount(2)
+ .returns("EXPR$0=null\n"
+ + "EXPR$0=null\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(EXPR$0=[ITEM($3, 'addressLine2')])\n"
+ + " GeodeSort(fetch=[2])\n"
+ + " GeodeTableScan(table=[[geode, BookCustomer]])\n");
+ }
+
+ @Test
+ public void testFilterWithNestedField() {
+ calciteAssert()
+ .query("SELECT primaryAddress['postalCode'] AS postalCode\n"
+ + "FROM geode.BookCustomer\n"
+ + "WHERE primaryAddress['postalCode'] > '0'\n")
+ .returnsCount(3)
+ .returns("postalCode=50505\n"
+ + "postalCode=50505\n"
+ + "postalCode=50505\n")
+ .explainContains("PLAN=GeodeToEnumerableConverter\n"
+ + " GeodeProject(postalCode=[ITEM($3, 'postalCode')])\n"
+ + " GeodeFilter(condition=[>(ITEM($3, 'postalCode'), '0')])\n"
+ + " GeodeTableScan(table=[[geode, BookCustomer]])\n");
+ }
+
+ @Test
+ public void testSqlSimple() throws SQLException {
+ calciteAssert()
+ .query("SELECT itemNumber FROM geode.BookMaster WHERE itemNumber > 123")
+ .runs();
+ }
+
+ @Test
+ public void testSqlSingleNumberWhereFilter() throws SQLException {
+ calciteAssert().query("SELECT * FROM geode.BookMaster "
+ + "WHERE itemNumber = 123").runs();
+ }
+
+ @Test
+ public void testSqlDistinctSort() throws SQLException {
+ calciteAssert().query("SELECT DISTINCT itemNumber, author "
+ + "FROM geode.BookMaster ORDER BY itemNumber, author").runs();
+ }
+
+ @Test
+ public void testSqlDistinctSort2() throws SQLException {
+ calciteAssert().query("SELECT itemNumber, author "
+ + "FROM geode.BookMaster GROUP BY itemNumber, author ORDER BY itemNumber, "
+ + "author").runs();
+ }
+
+ @Test
+ public void testSqlDistinctSort3() throws SQLException {
+ calciteAssert().query("SELECT DISTINCT * FROM geode.BookMaster").runs();
+ }
+
+
+ @Test
+ public void testSqlLimit2() throws SQLException {
+ calciteAssert().query("SELECT DISTINCT * FROM geode.BookMaster LIMIT 2").runs();
+ }
+
+
+ @Test
+ public void testSqlDisjunciton() throws SQLException {
+ calciteAssert().query("SELECT author FROM geode.BookMaster "
+ + "WHERE itemNumber = 789 OR itemNumber = 123").runs();
+ }
+
+ @Test
+ public void testSqlConjunciton() throws SQLException {
+ calciteAssert().query("SELECT author FROM geode.BookMaster "
+ + "WHERE itemNumber = 789 AND author = 'Jim Heavisides'").runs();
+ }
+
+ @Test
+ public void testSqlBookMasterWhere() throws SQLException {
+ calciteAssert().query("select author, title from geode.BookMaster "
+ + "WHERE author = 'Jim Heavisides' LIMIT 2")
+ .runs();
+ }
+
+ @Test
+ public void testSqlBookMasterCount() throws SQLException {
+ calciteAssert().query("select count(*) from geode.BookMaster").runs();
+ }
+
+}
+
+// End GeodeBookstoreTest.java