Repository: calcite Updated Branches: refs/heads/master b76affcce -> f3caf13b9
http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/elasticsearch/src/test/java/org/apache/calcite/test/ElasticsearchAdapterIT.java ---------------------------------------------------------------------- diff --git a/elasticsearch/src/test/java/org/apache/calcite/test/ElasticsearchAdapterIT.java b/elasticsearch/src/test/java/org/apache/calcite/test/ElasticsearchAdapterIT.java new file mode 100644 index 0000000..d99351e --- /dev/null +++ b/elasticsearch/src/test/java/org/apache/calcite/test/ElasticsearchAdapterIT.java @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.test; + +import org.apache.calcite.util.Util; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; + +import org.junit.Test; + +import java.util.List; +import javax.annotation.Nullable; + +/** + * Tests for the {@code org.apache.calcite.adapter.elasticsearch} package. + * + * <p>Before calling this test, you need to populate Elasticsearch, as follows: + * + * <blockquote><code> + * git clone https://github.com/vlsi/calcite-test-dataset<br> + * cd calcite-test-dataset<br> + * mvn install + * </code></blockquote> + * + * This will create a virtual machine with Elasticsearch and the "zips" test + * dataset. + */ +public class ElasticsearchAdapterIT { + /** + * Whether to run Elasticsearch tests. Enabled by default, however test is only + * included if "it" profile is activated ({@code -Pit}). To disable, + * specify {@code -Dcalcite.test.elasticsearch=false} on the Java command line. + */ + private static final boolean ENABLED = Util.getBooleanProperty("calcite.test.elasticsearch", + true); + + /** Connection factory based on the "zips-es" model. */ + private static final ImmutableMap<String, String> ZIPS = ImmutableMap.of("model", + ElasticsearchAdapterIT.class.getResource("/elasticsearch-zips-model.json").getPath()); + + /** Whether to run this test. */ + private boolean enabled() { + return ENABLED; + } + + /** Returns a function that checks that a particular Elasticsearch pipeline is + * generated to implement a query. */ + private static Function<List, Void> elasticsearchChecker(final String... strings) { + return new Function<List, Void>() { + @Nullable + @Override public Void apply(@Nullable List actual) { + Object[] actualArray = actual == null || actual.isEmpty() ? null + : ((List) actual.get(0)).toArray(); + CalciteAssert.assertArrayEqual("expected Elasticsearch query not found", strings, + actualArray); + return null; + } + }; + } + + @Test public void testSort() { + final String explain = "PLAN=ElasticsearchToEnumerableConverter\n" + + " ElasticsearchSort(sort0=[$4], dir0=[ASC])\n" + + " ElasticsearchProject(city=[CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], longitude=[CAST(ITEM(ITEM($0, 'loc'), 0)):FLOAT], latitude=[CAST(ITEM(ITEM($0, 'loc'), 1)):FLOAT], pop=[CAST(ITEM($0, 'pop')):INTEGER], state=[CAST(ITEM($0, 'state')):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], id=[CAST(ITEM($0, 'id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n" + + " ElasticsearchTableScan(table=[[elasticsearch_raw, zips]])"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select * from zips order by \"state\"") + .returnsCount(10) + .explainContains(explain); + } + + @Test public void testSortLimit() { + final String sql = "select \"state\", \"id\" from zips\n" + + "order by \"state\", \"id\" offset 2 rows fetch next 3 rows only"; + CalciteAssert.that() + .with(ZIPS) + .query(sql) + .returnsUnordered("state=AK; id=99503", + "state=AK; id=99504", + "state=AK; id=99505") + .queryContains( + elasticsearchChecker( + "\"fields\" : [\"state\", \"id\"], \"script_fields\": {}", + "\"sort\": [ {\"state\": \"asc\"}, {\"id\": \"asc\"}]", + "\"from\": 2", + "\"size\": 3")); + } + + @Test public void testOffsetLimit() { + final String sql = "select \"state\", \"id\" from zips\n" + + "offset 2 fetch next 3 rows only"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .runs() + .queryContains( + elasticsearchChecker( + "\"from\": 2", + "\"size\": 3", + "\"fields\" : [\"state\", \"id\"], \"script_fields\": {}")); + } + + @Test public void testLimit() { + final String sql = "select \"state\", \"id\" from zips\n" + + "fetch next 3 rows only"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .runs() + .queryContains( + elasticsearchChecker( + "\"size\": 3", + "\"fields\" : [\"state\", \"id\"], \"script_fields\": {}")); + } + + @Test public void testFilterSort() { + final String sql = "select * from zips\n" + + "where \"city\" = 'SPRINGFIELD' and \"id\" >= '70000'\n" + + "order by \"state\", \"id\""; + final String explain = "PLAN=ElasticsearchToEnumerableConverter\n" + + " ElasticsearchSort(sort0=[$4], sort1=[$5], dir0=[ASC], dir1=[ASC])\n" + + " ElasticsearchProject(city=[CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], longitude=[CAST(ITEM(ITEM($0, 'loc'), 0)):FLOAT], latitude=[CAST(ITEM(ITEM($0, 'loc'), 1)):FLOAT], pop=[CAST(ITEM($0, 'pop')):INTEGER], state=[CAST(ITEM($0, 'state')):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], id=[CAST(ITEM($0, 'id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n" + + " ElasticsearchFilter(condition=[AND(=(CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'SPRINGFIELD'), >=(CAST(ITEM($0, 'id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", '70000'))])\n" + + " ElasticsearchTableScan(table=[[elasticsearch_raw, zips]])"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .returnsOrdered( + "city=SPRINGFIELD; longitude=-92.54567; latitude=35.274879; pop=752; state=AR; id=72157", + "city=SPRINGFIELD; longitude=-102.617322; latitude=37.406727; pop=1992; state=CO; id=81073", + "city=SPRINGFIELD; longitude=-90.577479; latitude=30.415738; pop=5597; state=LA; id=70462", + "city=SPRINGFIELD; longitude=-123.015259; latitude=44.06106; pop=32384; state=OR; id=97477", + "city=SPRINGFIELD; longitude=-122.917108; latitude=44.056056; pop=27521; state=OR; id=97478") + .queryContains( + elasticsearchChecker("\"query\" : {\"constant_score\":{\"filter\":{\"bool\":" + + "{\"must\":[{\"term\":{\"city\":\"springfield\"}},{\"range\":{\"id\":{\"gte\":\"70000\"}}}]}}}}", + "\"fields\" : [\"city\", \"pop\", \"state\", \"id\"], \"script_fields\": {\"longitude\":{\"script\":\"_source.loc[0]\"}, \"latitude\":{\"script\":\"_source.loc[1]\"}}", + "\"sort\": [ {\"state\": \"asc\"}, {\"id\": \"asc\"}]")) + .explainContains(explain); + } + + @Test public void testFilterSortDesc() { + final String sql = "select * from zips\n" + + "where \"pop\" BETWEEN 20000 AND 20100\n" + + "order by \"state\" desc, \"pop\""; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .limit(4) + .returnsOrdered( + "city=SHERIDAN; longitude=-106.964795; latitude=44.78486; pop=20025; state=WY; id=82801", + "city=MOUNTLAKE TERRAC; longitude=-122.304036; latitude=47.793061; pop=20059; state=WA; id=98043", + "city=FALMOUTH; longitude=-77.404537; latitude=38.314557; pop=20039; state=VA; id=22405", + "city=FORT WORTH; longitude=-97.318409; latitude=32.725551; pop=20012; state=TX; id=76104"); + } + + @Test public void testFilterRedundant() { + final String sql = "select * from zips\n" + + "where \"state\" > 'CA' and \"state\" < 'AZ' and \"state\" = 'OK'"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .runs() + .queryContains( + elasticsearchChecker("" + + "\"query\" : {\"constant_score\":{\"filter\":{\"bool\":" + + "{\"must\":[{\"term\":{\"state\":\"ok\"}}]}}}}", + "\"fields\" : [\"city\", \"pop\", \"state\", \"id\"], \"script_fields\": {\"longitude\":{\"script\":\"_source.loc[0]\"}, \"latitude\":{\"script\":\"_source.loc[1]\"}}")); + } + + @Test public void testInPlan() { + final String[] searches = { + "\"query\" : {\"constant_score\":{\"filter\":{\"bool\":{\"should\":" + + "[{\"bool\":{\"must\":[{\"term\":{\"pop\":20012}}]}},{\"bool\":{\"must\":[{\"term\":" + + "{\"pop\":15590}}]}}]}}}}", + "\"fields\" : [\"city\", \"pop\", \"state\", \"id\"], \"script_fields\": {\"longitude\":{\"script\":\"_source.loc[0]\"}, \"latitude\":{\"script\":\"_source.loc[1]\"}}" + }; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select * from zips where \"pop\" in (20012, 15590)") + .returnsUnordered( + "city=COVINA; longitude=-117.884285; latitude=34.08596; pop=15590; state=CA; id=91723", + "city=ARLINGTON; longitude=-97.091987; latitude=32.654752; pop=15590; state=TX; id=76018", + "city=CROFTON; longitude=-76.680166; latitude=39.011163; pop=15590; state=MD; id=21114", + "city=FORT WORTH; longitude=-97.318409; latitude=32.725551; pop=20012; state=TX; id=76104", + "city=DINUBA; longitude=-119.39087; latitude=36.534931; pop=20012; state=CA; id=93618") + .queryContains(elasticsearchChecker(searches)); + } + + @Test public void testZips() { + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select \"state\", \"city\" from zips") + .returnsCount(10); + } + + @Test public void testProject() { + final String sql = "select \"state\", \"city\", 0 as \"zero\"\n" + + "from zips\n" + + "order by \"state\", \"city\""; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query(sql) + .limit(2) + .returnsUnordered("state=AK; city=ELMENDORF AFB; zero=0", + "state=AK; city=EIELSON AFB; zero=0") + .queryContains( + elasticsearchChecker("\"sort\": [ {\"state\": \"asc\"}, {\"city\": \"asc\"}]", + "\"fields\" : [\"state\", \"city\"], \"script_fields\": {\"zero\":{\"script\": \"0\"}}")); + } + + @Test public void testFilter() { + final String explain = "PLAN=ElasticsearchToEnumerableConverter\n" + + " ElasticsearchProject(state=[CAST(ITEM($0, 'state')):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], city=[CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n" + + " ElasticsearchFilter(condition=[=(CAST(ITEM($0, 'state')):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'CA')])\n" + + " ElasticsearchTableScan(table=[[elasticsearch_raw, zips]])"; + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select \"state\", \"city\" from zips where \"state\" = 'CA'") + .limit(2) + .returnsUnordered("state=CA; city=LOS ANGELES", + "state=CA; city=LOS ANGELES") + .explainContains(explain); + } + + @Test public void testFilterReversed() { + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select \"state\", \"city\" from zips where 'WI' < \"state\"") + .limit(2) + .returnsUnordered("state=WV; city=WELCH", + "state=WV; city=HANOVER"); + CalciteAssert.that() + .enable(enabled()) + .with(ZIPS) + .query("select \"state\", \"city\" from zips where \"state\" > 'WI'") + .limit(2) + .returnsUnordered("state=WV; city=WELCH", + "state=WV; city=HANOVER"); + } +} + +// End ElasticsearchAdapterIT.java http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/elasticsearch/src/test/resources/elasticsearch-zips-model.json ---------------------------------------------------------------------- diff --git a/elasticsearch/src/test/resources/elasticsearch-zips-model.json b/elasticsearch/src/test/resources/elasticsearch-zips-model.json new file mode 100644 index 0000000..dcbf2a4 --- /dev/null +++ b/elasticsearch/src/test/resources/elasticsearch-zips-model.json @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "version": "1.0", + "defaultSchema": "elasticsearch", + "schemas": [ + { + "type": "custom", + "name": "elasticsearch_raw", + "factory": "org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory", + "operand": { + "coordinates": "{'127.0.0.1': 9300}", + "userConfig": "{'bulk.flush.max.actions': 10, 'bulk.flush.max.size.mb': 1}", + "index": "usa" + } + }, + { + "name": "elasticsearch", + "tables": [ + { + "name": "ZIPS", + "type": "view", + "sql": [ + "select cast(_MAP['city'] AS varchar(20)) AS \"city\",\n", + " cast(_MAP['loc'][0] AS float) AS \"longitude\",\n", + " cast(_MAP['loc'][1] AS float) AS \"latitude\",\n", + " cast(_MAP['pop'] AS integer) AS \"pop\",\n", + " cast(_MAP['state'] AS varchar(2)) AS \"state\",\n", + " cast(_MAP['id'] AS varchar(5)) AS \"id\"\n", + "from \"elasticsearch_raw\".\"zips\"" + ] + } + ] + } + ] +} http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/elasticsearch/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/elasticsearch/src/test/resources/log4j.properties b/elasticsearch/src/test/resources/log4j.properties new file mode 100644 index 0000000..834e2db --- /dev/null +++ b/elasticsearch/src/test/resources/log4j.properties @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Root logger is configured at INFO and is sent to A1 +log4j.rootLogger=INFO, A1 + +# A1 goes to the console +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# 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/f3caf13b/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index b12e430..063f16d 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ limitations under the License. <commons-lang3.version>3.2</commons-lang3.version> <commons-logging.version>1.1.3</commons-logging.version> <eigenbase-properties.version>1.1.5</eigenbase-properties.version> + <elasticsearch-java-driver.version>2.3.2</elasticsearch-java-driver.version> <findbugs.version>1.3.9</findbugs.version> <fmpp-maven-plugin.version>1.0</fmpp-maven-plugin.version> <foodmart-data-hsqldb.version>0.3</foodmart-data-hsqldb.version> @@ -131,6 +132,7 @@ limitations under the License. <module>cassandra</module> <module>core</module> <module>druid</module> + <module>elasticsearch</module> <module>example</module> <module>linq4j</module> <module>mongodb</module> http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/site/_docs/adapter.md ---------------------------------------------------------------------- diff --git a/site/_docs/adapter.md b/site/_docs/adapter.md index b003e81..01a6995 100644 --- a/site/_docs/adapter.md +++ b/site/_docs/adapter.md @@ -30,6 +30,7 @@ presenting the data as tables within a schema. * [Cassandra adapter](cassandra_adapter.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/cassandra/package-summary.html">calcite-cassandra</a>) * CSV adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/csv/package-summary.html">example/csv</a>) * [Druid adapter](druid_adapter.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/druid/package-summary.html">calcite-druid</a>) +* [Elasticsearch adapter](elasticsearch_adapter.html) (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/elasticsearch/package-summary.html">calcite-elasticsearch</a>) * JDBC adapter (part of <a href="{{ site.apiRoot }}/org/apache/calcite/adapter/jdbc/package-summary.html">calcite-core</a>) * MongoDB adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/mongodb/package-summary.html">calcite-mongodb</a>) * Spark adapter (<a href="{{ site.apiRoot }}/org/apache/calcite/adapter/spark/package-summary.html">calcite-spark</a>) http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/site/_docs/elasticsearch_adapter.md ---------------------------------------------------------------------- diff --git a/site/_docs/elasticsearch_adapter.md b/site/_docs/elasticsearch_adapter.md new file mode 100644 index 0000000..d87d9e3 --- /dev/null +++ b/site/_docs/elasticsearch_adapter.md @@ -0,0 +1,136 @@ +--- +layout: docs +title: Elasticsearch adapter +permalink: /docs/elasticsearch_adapter.html +--- +<!-- +{% comment %} +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to you under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} +--> + +For instructions on downloading and building Calcite, start with the +[tutorial]({{ site.baseurl }}/docs/tutorial.html). + +Once you've managed to compile the project, you can return here to +start querying Elasticsearch with Calcite. First, we need a +[model definition]({{ site.baseurl }}/docs/model.html). +The model gives Calcite the necessary parameters to create an instance +of the Elasticsearch adapter. The models can contain +definitions of +[materializations]({{ site.baseurl }}/docs/model.html#materialization). +The name of the tables defined in the model definition corresponds to +[types](https://www.elastic.co/blog/what-is-an-elasticsearch-index) in +Elasticsearch. The schema/database is represented by the `index` parameter +in the model definition. + +A basic example of a model file is given below: + +{% highlight json %} +{ + "version": "1.0", + "defaultSchema": "elasticsearch", + "schemas": [ + { + "type": "custom", + "name": "elasticsearch", + "factory": "org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory", + "operand": { + "coordinates": "{'127.0.0.1': 9300}", + "userConfig": "{'bulk.flush.max.actions': 10, 'bulk.flush.max.size.mb': 1}", + "index": "usa" + } + } + ] +} +{% endhighlight %} + +Assuming this file is stored as `model.json`, you can connect to +Elasticsearch via [`sqlline`](https://github.com/julianhyde/sqlline) as +follows: + +{% highlight bash %} +$ ./sqlline +sqlline> !connect jdbc:calcite:model=model.json admin admin +{% endhighlight %} + +`sqlline` will now accept SQL queries which access your Elasticsearch types. +The purpose of this adapter is to compile the query into the most efficient +Elasticsearch SEARCH JSON possible by exploiting filtering and sorting directly +in Elasticsearch where possible. + +For example, in the example dataset there is an Elasticsearch type +named `zips` under index named `usa`. + +We can issue a simple query to fetch the names of all the states +stored in the type `zips`. By default, Elasticsearch returns only 10 rows: + +{% highlight sql %} +sqlline> SELECT * from "zips"; +{% endhighlight %} + +{% highlight json %} +_MAP={pop=13367, loc=[-72.505565, 42.067203], city=EAST LONGMEADOW, id=01028, state=MA} +_MAP={pop=1652, loc=[-72.908793, 42.070234], city=TOLLAND, id=01034, state=MA} +_MAP={pop=3184, loc=[-72.616735, 42.38439], city=HATFIELD, id=01038, state=MA} +_MAP={pop=43704, loc=[-72.626193, 42.202007], city=HOLYOKE, id=01040, state=MA} +_MAP={pop=2084, loc=[-72.873341, 42.265301], city=HUNTINGTON, id=01050, state=MA} +_MAP={pop=1350, loc=[-72.703403, 42.354292], city=LEEDS, id=01053, state=MA} +_MAP={pop=8194, loc=[-72.319634, 42.101017], city=MONSON, id=01057, state=MA} +_MAP={pop=1732, loc=[-72.204592, 42.062734], city=WALES, id=01081, state=MA} +_MAP={pop=9808, loc=[-72.258285, 42.261831], city=WARE, id=01082, state=MA} +_MAP={pop=4441, loc=[-72.203639, 42.20734], city=WEST WARREN, id=01092, state=MA} +{% endhighlight %} + +While executing this query, the Elasticsearch adapter is able to recognize +that `city` can be filtered by Elasticsearch and `state` can be sorted by +Elasticsearch in ascending order. + +The final source json given to Elasticsearch is below: + +{% highlight json %} +{ + "query": { + "constant_score": { + "filter": { + "bool": { + "must": [ + { + "term": { + "city": "springfield" + } + } + ] + } + } + } + }, + "fields": [ + "city", + "state" + ], + "script_fields": {}, + "sort": [ + { + "state": "asc" + } + ] +} +{% endhighlight %} + +This is the initial version of the Calcite Elasticsearch adapter. +Work is in progress to introduce new features like aggregations into +it. http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/sqlline ---------------------------------------------------------------------- diff --git a/sqlline b/sqlline index e1b13c7..9e111a2 100755 --- a/sqlline +++ b/sqlline @@ -37,7 +37,7 @@ if [ ! -f target/fullclasspath.txt ]; then fi CP= -for module in core avatica cassandra druid mongodb spark splunk example/csv example/function; do +for module in core avatica cassandra druid elasticsearch mongodb spark splunk example/csv example/function; do CP=${CP}${module}/target/classes: CP=${CP}${module}/target/test-classes: done http://git-wip-us.apache.org/repos/asf/calcite/blob/f3caf13b/sqlline.bat ---------------------------------------------------------------------- diff --git a/sqlline.bat b/sqlline.bat index b9a4875..50e9701 100644 --- a/sqlline.bat +++ b/sqlline.bat @@ -23,6 +23,6 @@ :: Copy dependency jars on first call. (To force jar refresh, remove target\dependencies) if not exist target\dependencies (call mvn -B dependency:copy-dependencies -DoverWriteReleases=false -DoverWriteSnapshots=false -DoverWriteIfNewer=true -DoutputDirectory=target\dependencies) -java -Xmx1G -cp ".\target\dependencies\*;core\target\dependencies\*;avatica\target\dependencies\*;cassandra\target\dependencies\*;mongodb\target\dependencies\*;spark\target\dependencies\*;splunk\target\dependencies\*" sqlline.SqlLine --verbose=true %* +java -Xmx1G -cp ".\target\dependencies\*;core\target\dependencies\*;avatica\target\dependencies\*;cassandra\target\dependencies\*;elasticsearch\target\dependencies\*;mongodb\target\dependencies\*;spark\target\dependencies\*;splunk\target\dependencies\*" sqlline.SqlLine --verbose=true %* :: End sqlline.bat
