-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sql add support for geo shape type (#4204)
Adds initial very minimal support for geo_shapes to SQL. For now, geoshapes are converted into String instead of Geometry objects on the JDBC side and no effort to parse the result is performed. Relates #4080
- Loading branch information
Showing
24 changed files
with
1,286 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
}, | ||
"salary" : { | ||
"type" : "integer" | ||
}, | ||
"site": { | ||
"type": "geo_shape" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...no-security/src/test/java/org/elasticsearch/xpack/qa/sql/nosecurity/GeoJdbcCsvSpecIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.qa.sql.nosecurity; | ||
|
||
import org.elasticsearch.xpack.qa.sql.geo.GeoCsvSpecTestCase; | ||
import org.elasticsearch.xpack.qa.sql.jdbc.CsvTestUtils.CsvTestCase; | ||
|
||
public class GeoJdbcCsvSpecIT extends GeoCsvSpecTestCase { | ||
public GeoJdbcCsvSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase) { | ||
super(fileName, groupName, testName, lineNumber, testCase); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...no-security/src/test/java/org/elasticsearch/xpack/qa/sql/nosecurity/GeoJdbcSqlSpecIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.qa.sql.nosecurity; | ||
|
||
import org.elasticsearch.xpack.qa.sql.geo.GeoSqlSpecTestCase; | ||
|
||
public class GeoJdbcSqlSpecIT extends GeoSqlSpecTestCase { | ||
public GeoJdbcSqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, String query) { | ||
super(fileName, groupName, testName, lineNumber, query); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/geo/GeoCsvSpecTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.qa.sql.geo; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import org.elasticsearch.xpack.qa.sql.jdbc.CsvTestUtils.CsvTestCase; | ||
import org.elasticsearch.xpack.qa.sql.jdbc.SpecBaseIntegrationTestCase; | ||
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcConfiguration; | ||
import org.junit.Before; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import static org.elasticsearch.xpack.qa.sql.jdbc.CsvTestUtils.csvConnection; | ||
import static org.elasticsearch.xpack.qa.sql.jdbc.CsvTestUtils.executeCsvQuery; | ||
import static org.elasticsearch.xpack.qa.sql.jdbc.CsvTestUtils.specParser; | ||
|
||
/** | ||
* Tests comparing sql queries executed against our jdbc client | ||
* with hard coded result sets. | ||
*/ | ||
public abstract class GeoCsvSpecTestCase extends SpecBaseIntegrationTestCase { | ||
private final CsvTestCase testCase; | ||
|
||
@ParametersFactory(argumentFormatting = PARAM_FORMATTING) | ||
public static List<Object[]> readScriptSpec() throws Exception { | ||
Parser parser = specParser(); | ||
List<Object[]> tests = new ArrayList<>(); | ||
tests.addAll(readScriptSpec("/ogc/ogc.csv-spec", parser)); | ||
return tests; | ||
} | ||
|
||
public GeoCsvSpecTestCase(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase) { | ||
super(fileName, groupName, testName, lineNumber); | ||
this.testCase = testCase; | ||
} | ||
|
||
|
||
@Before | ||
public void setupTestGeoDataIfNeeded() throws Exception { | ||
if (client().performRequest("HEAD", "/ogc").getStatusLine().getStatusCode() == 404) { | ||
GeoDataLoader.loadDatasetIntoEs(client()); | ||
} | ||
} | ||
|
||
@Override | ||
protected final void doTest() throws Throwable { | ||
try (Connection csv = csvConnection(testCase.expectedResults); | ||
Connection es = esJdbc()) { | ||
|
||
// pass the testName as table for debugging purposes (in case the underlying reader is missing) | ||
ResultSet expected = executeCsvQuery(csv, testName); | ||
ResultSet elasticResults = executeJdbcQuery(es, testCase.query); | ||
assertResults(expected, elasticResults); | ||
} | ||
} | ||
|
||
// make sure ES uses UTC (otherwise JDBC driver picks up the JVM timezone per spec/convention) | ||
@Override | ||
protected Properties connectionProperties() { | ||
Properties connectionProperties = new Properties(); | ||
connectionProperties.setProperty(JdbcConfiguration.TIME_ZONE, "UTC"); | ||
return connectionProperties; | ||
} | ||
|
||
} |
Oops, something went wrong.