Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Add initial geo support #42031

Merged
merged 89 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
1157c11
Sql add support for geo shape type (#4204)
imotov May 8, 2018
f890bc6
Merge remote-tracking branch 'elastic/master' into geosql
imotov Jun 8, 2018
61e92f1
Fix qa-sql h2gis dependency
imotov Jun 8, 2018
b512e55
Merge remote-tracking branch 'elastic/master' into geosql
imotov Jun 11, 2018
62a2937
SQL: Add basic support for geo point (#31257)
imotov Jun 12, 2018
80e91cc
Merge remote-tracking branch 'elastic/master' into geosql
imotov Jul 16, 2018
cc5768e
Merge remote-tracking branch 'elastic/master' into geosql
imotov Aug 7, 2018
f73797a
Merge remote-tracking branch 'elastic/master' into geosql
imotov Sep 24, 2018
819045b
Tests: Fix client call in GeoDataLoader after merge
imotov Sep 24, 2018
2164893
Tests: add a workaround for testing timestamps in H2 v1.4.196
imotov Sep 25, 2018
642f1cf
Merge remote-tracking branch 'elastic/master' into geosql
imotov Sep 26, 2018
a561593
Tests: Fix merge in JdbcAssert
imotov Sep 26, 2018
6d6a0a4
Merge remote-tracking branch 'elastic/master' into geosql
imotov Oct 1, 2018
0301e6b
Merge remote-tracking branch 'elastic/master' into geosql
imotov Oct 18, 2018
0280428
SQL: Add basic support for ST_AsWKT geo function (#34205)
imotov Oct 23, 2018
09897ba
Merge remote-tracking branch 'elastic/master' into geosql
imotov Oct 23, 2018
49f859c
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 1, 2018
99d9e2f
SQL: Fix geosql show function tests after master merge
imotov Nov 2, 2018
6f0b2fb
SQL: Fix geo tests after move of qa directory
imotov Nov 2, 2018
8e79977
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 8, 2018
e5fd7f4
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 8, 2018
78dfa50
SQL: Fix logger in LocalH2-based tests
imotov Nov 8, 2018
76be286
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 9, 2018
bfedbbb
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 14, 2018
1ac1177
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 14, 2018
08da5bb
SQL: Add ST_WktToSQL function (#35416)
imotov Nov 15, 2018
52ddf5a
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 16, 2018
de31429
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 20, 2018
e35c9b7
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 21, 2018
69a27cf
Merge remote-tracking branch 'elastic/master' into geosql
imotov Nov 21, 2018
83023f3
Merge remote-tracking branch 'elastic/master' into geosql
imotov Dec 4, 2018
27aba15
Merge remote-tracking branch 'elastic/master' into geosql
imotov Dec 7, 2018
a039f10
Merge remote-tracking branch 'elastic/master' into geosql
imotov Jan 14, 2019
a5ad3f9
SQL: Fix compilation error in St-functions after master merge
imotov Jan 14, 2019
4b9da09
Merge remote-tracking branch 'elastic/master' into geosql
imotov Jan 15, 2019
d12a7a7
SQL: remove type from geo mappings
imotov Jan 15, 2019
dfaeaa9
Merge remote-tracking branch 'elastic/master' into geosql
imotov Feb 11, 2019
c715326
Merge remote-tracking branch 'elastic/master' into geosql
imotov Feb 19, 2019
d5d52f2
Merge remote-tracking branch 'elastic/master' into geosql
imotov Feb 20, 2019
3a0411f
Merge remote-tracking branch 'elastic/master' into geosql
imotov Feb 26, 2019
44542b0
SQL: Switch JDBC driver to libs/geo objects for geo_shapes (#39204)
imotov Feb 27, 2019
787eef6
Merge remote-tracking branch 'elastic/master' into geosql
imotov Feb 27, 2019
078dcf0
SQL: Switch JDBC driver to libs/geo objects for geo_points (#39484)
imotov Mar 1, 2019
d497ba2
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 1, 2019
8d1d944
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 4, 2019
0ff9e3c
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 7, 2019
943f4eb
SQL: suppress Geosql tests if locale doesn't use - for negative numbe…
imotov Mar 8, 2019
584b74c
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 12, 2019
2ba546e
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 20, 2019
223f756
SQL: Make TIME_ZONE constant public for geosql
imotov Mar 20, 2019
82ad403
SQL: Add ST_Distance function to geosql (#39973)
imotov Mar 22, 2019
415d651
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 22, 2019
ece7d92
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 25, 2019
1ad9d0b
SQL: Upgrade H2GIS library to 1.5.0 (#40461)
imotov Mar 27, 2019
f44f35d
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 27, 2019
886830f
Merge remote-tracking branch 'elastic/master' into geosql
imotov Mar 28, 2019
b4231c9
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 1, 2019
ed0c0e6
SQL: Convert ST_Distance into query when possible (#40595)
imotov Apr 2, 2019
1ac266a
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 2, 2019
513eba1
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 9, 2019
ee64cc9
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 9, 2019
d7647c8
SQL: Improve null handling in Geo Functions (#40708)
imotov Apr 10, 2019
c6d611b
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 10, 2019
07ad376
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 14, 2019
dd07273
SQL: Add ST_X, ST_Y and ST_GEOMETRY_TYPE functions (#41104)
imotov Apr 22, 2019
d7e4c46
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 22, 2019
1543cf7
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 23, 2019
d193922
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 28, 2019
01b6c79
Merge remote-tracking branch 'elastic/master' into geosql
imotov Apr 30, 2019
00e9c79
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 2, 2019
b2f0435
SQL: Switch server side for geosql from ShapeBuilder to libs/geo (#41…
imotov May 2, 2019
7b8ab09
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 3, 2019
d5a43c3
SQL: Add ST_Z function (#41772)
imotov May 6, 2019
7e1999a
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 6, 2019
a3c138a
Update TLS ciphers and protocols for JDK 11 (#41808)
jaymode May 7, 2019
502b395
Correct spelling of MockLogAppender.PatternSeenEventExpectation (#41893)
romseygeek May 7, 2019
a99fc23
Handle serialization exceptions during publication (#41781)
DaveCTurner May 7, 2019
8bff716
[DOCS] Fix callouts for dataframe APIs (#41904)
lcawl May 7, 2019
1559a8e
SQL: Remove CircuitBreaker from parser (#41835)
matriv May 7, 2019
907b917
SQL: Add non-zero display size for geo types (#41869)
imotov May 7, 2019
62f9606
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 7, 2019
e9e7f33
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 8, 2019
1f2b580
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 8, 2019
da72ce1
SQL: Improve error messages for geo_shape (#41923)
imotov May 9, 2019
8398455
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 9, 2019
87f74f8
Remove unnecessary binary files in x-pack/plugin/ml/cpp-snapshot/.cache
imotov May 9, 2019
b51dfef
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 9, 2019
a17603c
Merge remote-tracking branch 'elastic/master' into geosql
imotov May 13, 2019
881a357
Fix tests to work with #41558
imotov May 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions docs/reference/sql/functions/geo.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
[role="xpack"]
[testenv="basic"]
[[sql-functions-geo]]
=== Geo Functions

The geo functions work with geometries stored in `geo_point` and `geo_shape` fields, or returned by other geo functions.

==== Limitations

Both <<geo-point, `geo_point`>> and <<geo-shape, `geo_shape`>> types are represented in SQL as geometry and can be used
interchangeably with the following exceptions:

* `geo_shape` fields don't have doc values, therefore these fields cannot be used for filtering, grouping or sorting.

* `geo_points` fields are indexed and have doc values by default, however only latitude and longitude are stored and
indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and
8.381903171539307E-8 for longitude). The altitude component is accepted but not stored in doc values nor indexed.
Therefore calling `ST_Z` function in the filtering, grouping or sorting will return `null`.

==== Geometry Conversion

[[sql-functions-geo-st-as-wkt]]
===== `ST_AsWKT`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_AsWKT(geometry<1>)
--------------------------------------------------

*Input*:

<1> geometry

*Output*: string

.Description:

Returns the WKT representation of the `geometry`.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt]
--------------------------------------------------


[[sql-functions-geo-st-wkt-to-sql]]
===== `ST_WKTToSQL`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_WKTToSQL(string<1>)
--------------------------------------------------

*Input*:

<1> string WKT representation of geometry

*Output*: geometry

.Description:

Returns the geometry from WKT representation.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[aswkt]
--------------------------------------------------

==== Geometry Properties

[[sql-functions-geo-st-geometrytype]]
===== `ST_GeometryType`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_GeometryType(geometry<1>)
--------------------------------------------------

*Input*:

<1> geometry

*Output*: string

.Description:

Returns the type of the `geometry` such as POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON, GEOMETRYCOLLECTION, ENVELOPE or CIRCLE.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[geometrytype]
--------------------------------------------------

[[sql-functions-geo-st-x]]
===== `ST_X`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_X(geometry<1>)
--------------------------------------------------

*Input*:

<1> geometry

*Output*: double

.Description:

Returns the longitude of the first point in the geometry.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[x]
--------------------------------------------------

[[sql-functions-geo-st-y]]
===== `ST_Y`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_Y(geometry<1>)
--------------------------------------------------

*Input*:

<1> geometry

*Output*: double

.Description:

Returns the the latitude of the first point in the geometry.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[y]
--------------------------------------------------

[[sql-functions-geo-st-z]]
===== `ST_Z`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_Z(geometry<1>)
--------------------------------------------------

*Input*:

<1> geometry

*Output*: double

.Description:

Returns the altitude of the first point in the geometry.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[z]
--------------------------------------------------

[[sql-functions-geo-st-distance]]
===== `ST_Distance`

.Synopsis:
[source, sql]
--------------------------------------------------
ST_Distance(geometry<1>, geometry<2>)
--------------------------------------------------

*Input*:

<1> source geometry
<2> target geometry

*Output*: Double

.Description:

Returns the distance between geometries in meters. Both geometries have to be points.

["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs/geo.csv-spec[distance]
--------------------------------------------------
9 changes: 9 additions & 0 deletions docs/reference/sql/functions/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@
** <<sql-functions-conditional-least>>
** <<sql-functions-conditional-nullif>>
** <<sql-functions-conditional-nvl>>
* <<sql-functions-geo>>
** <<sql-functions-geo-st-as-wkt>>
** <<sql-functions-geo-st-distance>>
** <<sql-functions-geo-st-geometrytype>>
** <<sql-functions-geo-st-wkt-to-sql>>
** <<sql-functions-geo-st-x>>
** <<sql-functions-geo-st-y>>
** <<sql-functions-geo-st-z>>
* <<sql-functions-system>>
** <<sql-functions-system-database>>
** <<sql-functions-system-user>>
Expand All @@ -149,5 +157,6 @@ include::search.asciidoc[]
include::math.asciidoc[]
include::string.asciidoc[]
include::type-conversion.asciidoc[]
include::geo.asciidoc[]
include::conditional.asciidoc[]
include::system.asciidoc[]
2 changes: 2 additions & 0 deletions docs/reference/sql/language/data-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ s|SQL precision
| interval_hour_to_minute | 23
| interval_hour_to_second | 23
| interval_minute_to_second | 23
| geo_point | 52
| geo_shape | 2,147,483,647

|===

Expand Down
11 changes: 11 additions & 0 deletions docs/reference/sql/limitations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ SELECT count(*) FROM test GROUP BY MINUTE((CAST(date_created AS TIME));
-------------------------------------------------------------
SELECT HISTOGRAM(CAST(birth_date AS TIME), INTERVAL '10' MINUTES) as h, COUNT(*) FROM t GROUP BY h
-------------------------------------------------------------

[float]
[[geo-sql-limitations]]
=== Geo-related functions

Since `geo_shape` fields don't have doc values these fields cannot be used for filtering, grouping or sorting.

By default,`geo_points` fields are indexed and have doc values. However only latitude and longitude are stored and
indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and
8.381903171539307E-8 for longitude). The altitude component is accepted but not stored in doc values nor indexed.
Therefore calling `ST_Z` function in the filtering, grouping or sorting will return `null`.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@

import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.BaseGeoShapeFieldMapper;

import java.io.IOException;
import java.io.InputStream;

/**
* first point of entry for a shape parser
Expand Down Expand Up @@ -67,4 +73,20 @@ static ShapeBuilder parse(XContentParser parser, BaseGeoShapeFieldMapper shapeMa
static ShapeBuilder parse(XContentParser parser) throws IOException {
return parse(parser, null);
}

static ShapeBuilder parse(Object value) throws IOException {
XContentBuilder content = JsonXContent.contentBuilder();
content.startObject();
content.field("value", value);
content.endObject();

try (InputStream stream = BytesReference.bytes(content).streamInput();
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) {
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // field value
return parse(parser);
}
}
}
1 change: 1 addition & 0 deletions x-pack/plugin/sql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ext {
// SQL test dependency versions
csvjdbcVersion="1.0.34"
h2Version="1.4.197"
h2gisVersion="1.5.0"
}

configurations {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugin/sql/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ dependencies {
compile (project(':libs:x-content')) {
transitive = false
}
compile (project(':libs:elasticsearch-geo')) {
transitive = false
}
compile project(':libs:core')
runtime "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
testCompile "org.elasticsearch.test:framework:${version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public enum EsType implements SQLType {
INTERVAL_DAY_TO_SECOND( ExtraTypes.INTERVAL_DAY_SECOND),
INTERVAL_HOUR_TO_MINUTE( ExtraTypes.INTERVAL_HOUR_MINUTE),
INTERVAL_HOUR_TO_SECOND( ExtraTypes.INTERVAL_HOUR_SECOND),
INTERVAL_MINUTE_TO_SECOND(ExtraTypes.INTERVAL_MINUTE_SECOND);
INTERVAL_MINUTE_TO_SECOND(ExtraTypes.INTERVAL_MINUTE_SECOND),
GEO_POINT( ExtraTypes.GEOMETRY),
GEO_SHAPE( ExtraTypes.GEOMETRY);

private final Integer type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ private ExtraTypes() {}
static final int INTERVAL_HOUR_MINUTE = 111;
static final int INTERVAL_HOUR_SECOND = 112;
static final int INTERVAL_MINUTE_SECOND = 113;
static final int GEOMETRY = 114;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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.sql.jdbc;

import java.util.Objects;
Expand Down Expand Up @@ -89,4 +90,4 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(name, type, table, catalog, schema, label, displaySize);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/ Additional properties can be specified either through the Properties object or in the URL. In case of duplicates, the URL wins.
*/
//TODO: beef this up for Security/SSL
class JdbcConfiguration extends ConnectionConfiguration {
public class JdbcConfiguration extends ConnectionConfiguration {
static final String URL_PREFIX = "jdbc:es://";
public static URI DEFAULT_URI = URI.create("http://localhost:9200/");

Expand All @@ -47,7 +47,7 @@ class JdbcConfiguration extends ConnectionConfiguration {
// can be out/err/url
static final String DEBUG_OUTPUT_DEFAULT = "err";

static final String TIME_ZONE = "timezone";
public static final String TIME_ZONE = "timezone";
// follow the JDBC spec and use the JVM default...
// to avoid inconsistency, the default is picked up once at startup and reused across connections
// to cater to the principle of least surprise
Expand Down
Loading