Skip to content

Commit 76de93c

Browse files
authored
SQL: Add support for shape type (elastic#46464)
Enables support for Cartesian geometries shape type. We still need to decide how to handle the distance function since it is currently using the haversine distance formula and returns results in meters, which doesn't make any sense for Cartesian geometries. Closes elastic#46412 Relates to elastic#43644
1 parent b42923f commit 76de93c

File tree

20 files changed

+147
-115
lines changed

20 files changed

+147
-115
lines changed

docs/reference/sql/functions/geo.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
beta[]
77

8-
The geo functions work with geometries stored in `geo_point` and `geo_shape` fields, or returned by other geo functions.
8+
The geo functions work with geometries stored in `geo_point`, `geo_shape` and `shape` fields, or returned by other geo functions.
99

1010
==== Limitations
1111

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

15-
* `geo_shape` fields don't have doc values, therefore these fields cannot be used for filtering, grouping or sorting.
15+
* `geo_shape` and `shape` fields don't have doc values, therefore these fields cannot be used for filtering, grouping
16+
or sorting.
1617

1718
* `geo_points` fields are indexed and have doc values by default, however only latitude and longitude are stored and
1819
indexed with some loss of precision from the original values (4.190951585769653E-8 for the latitude and

docs/reference/sql/language/data-types.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ s|SQL precision
8383
| interval_minute_to_second | 23
8484
| geo_point | 52
8585
| geo_shape | 2,147,483,647
86+
| shape | 2,147,483,647
8687

8788
|===
8889

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/EsType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.sql.Types;
1212

1313
public enum EsType implements SQLType {
14-
14+
1515
NULL( Types.NULL),
1616
UNSUPPORTED( Types.OTHER),
1717
BOOLEAN( Types.BOOLEAN),
@@ -46,7 +46,8 @@ public enum EsType implements SQLType {
4646
INTERVAL_HOUR_TO_SECOND( ExtraTypes.INTERVAL_HOUR_SECOND),
4747
INTERVAL_MINUTE_TO_SECOND(ExtraTypes.INTERVAL_MINUTE_SECOND),
4848
GEO_POINT( ExtraTypes.GEOMETRY),
49-
GEO_SHAPE( ExtraTypes.GEOMETRY);
49+
GEO_SHAPE( ExtraTypes.GEOMETRY),
50+
SHAPE( ExtraTypes.GEOMETRY);
5051

5152
private final Integer type;
5253

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/TypeConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ static Object convert(Object v, EsType columnType, String typeString) throws SQL
248248
return Duration.parse(v.toString());
249249
case GEO_POINT:
250250
case GEO_SHAPE:
251+
case SHAPE:
251252
try {
252253
return WKT.fromWKT(v.toString());
253254
} catch (IOException | ParseException ex) {

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/TypeUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private TypeUtils() {}
9494
types.put(EsType.INTERVAL_MINUTE_TO_SECOND, Duration.class);
9595
types.put(EsType.GEO_POINT, String.class);
9696
types.put(EsType.GEO_SHAPE, String.class);
97+
types.put(EsType.SHAPE, String.class);
9798

9899
TYPE_TO_CLASS = unmodifiableMap(types);
99100

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/geo/GeoDataLoader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ private static String createOGCIndexRequest() throws Exception {
7373
createString("name", createIndex);
7474

7575
// Type specific
76-
createIndex.startObject("shore").field("type", "geo_shape").endObject(); // lakes
76+
createIndex.startObject("shore").field("type", "shape").endObject(); // lakes
7777

7878
createString("aliases", createIndex); // road_segments
7979
createIndex.startObject("num_lanes").field("type", "integer").endObject(); // road_segments, divided_routes
80-
createIndex.startObject("centerline").field("type", "geo_shape").endObject(); // road_segments, streams
80+
createIndex.startObject("centerline").field("type", "shape").endObject(); // road_segments, streams
8181

82-
createIndex.startObject("centerlines").field("type", "geo_shape").endObject(); // divided_routes
82+
createIndex.startObject("centerlines").field("type", "shape").endObject(); // divided_routes
8383

84-
createIndex.startObject("boundary").field("type", "geo_shape").endObject(); // forests, named_places
84+
createIndex.startObject("boundary").field("type", "shape").endObject(); // forests, named_places
8585

86-
createIndex.startObject("position").field("type", "geo_shape").endObject(); // bridges, buildings
86+
createIndex.startObject("position").field("type", "shape").endObject(); // bridges, buildings
8787

8888
createString("address", createIndex); // buildings
89-
createIndex.startObject("footprint").field("type", "geo_shape").endObject(); // buildings
89+
createIndex.startObject("footprint").field("type", "shape").endObject(); // buildings
9090

9191
createIndex.startObject("type").field("type", "keyword").endObject(); // ponds
92-
createIndex.startObject("shores").field("type", "geo_shape").endObject(); // ponds
92+
createIndex.startObject("shores").field("type", "shape").endObject(); // ponds
9393

94-
createIndex.startObject("neatline").field("type", "geo_shape").endObject(); // map_neatlines
94+
createIndex.startObject("neatline").field("type", "shape").endObject(); // map_neatlines
9595

9696
}
9797
createIndex.endObject();
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
city,region,region_point,location,shape
2-
Mountain View,Americas,POINT(-105.2551 54.5260),POINT (-122.083843 37.386483),POINT (-122.083843 37.386483)
3-
Chicago,Americas,POINT(-105.2551 54.5260),POINT (-87.637874 41.888783),POINT (-87.637874 41.888783)
4-
New York,Americas,POINT(-105.2551 54.5260),POINT (-73.990027 40.745171),POINT (-73.990027 40.745171)
5-
San Francisco,Americas,POINT(-105.2551 54.5260),POINT (-122.394228 37.789541),POINT (-122.394228 37.789541)
6-
Phoenix,Americas,POINT(-105.2551 54.5260),POINT (-111.973505 33.376242),POINT (-111.973505 33.376242)
7-
Amsterdam,Europe,POINT(15.2551 54.5260),POINT (4.850312 52.347557),POINT (4.850312 52.347557)
8-
Berlin,Europe,POINT(15.2551 54.5260),POINT (13.390889 52.486701),POINT (13.390889 52.486701)
9-
Munich,Europe,POINT(15.2551 54.5260),POINT (11.537505 48.146321),POINT (11.537505 48.146321)
10-
London,Europe,POINT(15.2551 54.5260),POINT (-0.121672 51.510871),POINT (-0.121672 51.510871)
11-
Paris,Europe,POINT(15.2551 54.5260),POINT (2.351773 48.845538),POINT (2.351773 48.845538)
12-
Singapore,Asia,POINT(100.6197 34.0479),POINT (103.855535 1.295868),POINT (103.855535 1.295868)
13-
Hong Kong,Asia,POINT(100.6197 34.0479),POINT (114.183925 22.281397),POINT (114.183925 22.281397)
14-
Seoul,Asia,POINT(100.6197 34.0479),POINT (127.060851 37.509132),POINT (127.060851 37.509132)
15-
Tokyo,Asia,POINT(100.6197 34.0479),POINT (139.76402225 35.669616),POINT (139.76402225 35.669616)
16-
Sydney,Asia,POINT(100.6197 34.0479),POINT (151.208629 -33.863385),POINT (151.208629 -33.863385)
1+
city,region,region_point,location,geoshape,shape
2+
Mountain View,Americas,POINT(-105.2551 54.5260),POINT (-122.083843 37.386483),POINT (-122.083843 37.386483)),POINT (-122.083843 37.386483)
3+
Chicago,Americas,POINT(-105.2551 54.5260),POINT (-87.637874 41.888783),POINT (-87.637874 41.888783),POINT (-87.637874 41.888783)
4+
New York,Americas,POINT(-105.2551 54.5260),POINT (-73.990027 40.745171),POINT (-73.990027 40.745171),POINT (-73.990027 40.745171)
5+
San Francisco,Americas,POINT(-105.2551 54.5260),POINT (-122.394228 37.789541),POINT (-122.394228 37.789541),POINT (-122.394228 37.789541)
6+
Phoenix,Americas,POINT(-105.2551 54.5260),POINT (-111.973505 33.376242),POINT (-111.973505 33.376242),POINT (-111.973505 33.376242)
7+
Amsterdam,Europe,POINT(15.2551 54.5260),POINT (4.850312 52.347557),POINT (4.850312 52.347557),POINT (4.850312 52.347557)
8+
Berlin,Europe,POINT(15.2551 54.5260),POINT (13.390889 52.486701),POINT (13.390889 52.486701),POINT (13.390889 52.486701)
9+
Munich,Europe,POINT(15.2551 54.5260),POINT (11.537505 48.146321),POINT (11.537505 48.146321),POINT (11.537505 48.146321)
10+
London,Europe,POINT(15.2551 54.5260),POINT (-0.121672 51.510871),POINT (-0.121672 51.510871),POINT (-0.121672 51.510871)
11+
Paris,Europe,POINT(15.2551 54.5260),POINT (2.351773 48.845538),POINT (2.351773 48.845538),POINT (2.351773 48.845538)
12+
Singapore,Asia,POINT(100.6197 34.0479),POINT (103.855535 1.295868),POINT (103.855535 1.295868),POINT (103.855535 1.295868)
13+
Hong Kong,Asia,POINT(100.6197 34.0479),POINT (114.183925 22.281397),POINT (114.183925 22.281397),POINT (114.183925 22.281397)
14+
Seoul,Asia,POINT(100.6197 34.0479),POINT (127.060851 37.509132),POINT (127.060851 37.509132),POINT (127.060851 37.509132)
15+
Tokyo,Asia,POINT(100.6197 34.0479),POINT (139.76402225 35.669616),POINT (139.76402225 35.669616),POINT (139.76402225 35.669616)
16+
Sydney,Asia,POINT(100.6197 34.0479),POINT (151.208629 -33.863385),POINT (151.208629 -33.863385),POINT (151.208629 -33.863385)
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{"index":{"_id": "1"}}
2-
{"region": "Americas", "city": "Mountain View", "location": {"lat":"37.386483", "lon":"-122.083843"}, "location_no_dv": {"lat":"37.386483", "lon":"-122.083843"}, "shape": "POINT (-122.083843 37.386483 30)", "region_point": "POINT(-105.2551 54.5260)"}
2+
{"region": "Americas", "city": "Mountain View", "location": {"lat":"37.386483", "lon":"-122.083843"}, "location_no_dv": {"lat":"37.386483", "lon":"-122.083843"}, "geoshape": "POINT (-122.083843 37.386483 30)", "shape": "POINT (-122.083843 37.386483 30)", "region_point": "POINT(-105.2551 54.5260)"}
33
{"index":{"_id": "2"}}
4-
{"region": "Americas", "city": "Chicago", "location": [-87.637874, 41.888783], "location_no_dv": [-87.637874, 41.888783], "shape": {"type" : "point", "coordinates" : [-87.637874, 41.888783, 181]}, "region_point": "POINT(-105.2551 54.5260)"}
4+
{"region": "Americas", "city": "Chicago", "location": [-87.637874, 41.888783], "location_no_dv": [-87.637874, 41.888783], "geoshape": {"type" : "point", "coordinates" : [-87.637874, 41.888783, 181]}, "shape": {"type" : "point", "coordinates" : [-87.637874, 41.888783, 181]}, "region_point": "POINT(-105.2551 54.5260)"}
55
{"index":{"_id": "3"}}
6-
{"region": "Americas", "city": "New York", "location": "40.745171,-73.990027", "location_no_dv": "40.745171,-73.990027", "shape": "POINT (-73.990027 40.745171 10)", "region_point": "POINT(-105.2551 54.5260)"}
6+
{"region": "Americas", "city": "New York", "location": "40.745171,-73.990027", "location_no_dv": "40.745171,-73.990027", "geoshape": "POINT (-73.990027 40.745171 10)", "shape": "POINT (-73.990027 40.745171 10)", "region_point": "POINT(-105.2551 54.5260)"}
77
{"index":{"_id": "4"}}
8-
{"region": "Americas", "city": "San Francisco", "location": "37.789541,-122.394228", "location_no_dv": "37.789541,-122.394228", "shape": "POINT (-122.394228 37.789541 16)", "region_point": "POINT(-105.2551 54.5260)"}
8+
{"region": "Americas", "city": "San Francisco", "location": "37.789541,-122.394228", "location_no_dv": "37.789541,-122.394228", "geoshape": "POINT (-122.394228 37.789541 16)", "shape": "POINT (-122.394228 37.789541 16)", "region_point": "POINT(-105.2551 54.5260)"}
99
{"index":{"_id": "5"}}
10-
{"region": "Americas", "city": "Phoenix", "location": "33.376242,-111.973505", "location_no_dv": "33.376242,-111.973505", "shape": "POINT (-111.973505 33.376242 331)", "region_point": "POINT(-105.2551 54.5260)"}
10+
{"region": "Americas", "city": "Phoenix", "location": "33.376242,-111.973505", "location_no_dv": "33.376242,-111.973505", "geoshape": "POINT (-111.973505 33.376242 331)", "shape": "POINT (-111.973505 33.376242 331)", "region_point": "POINT(-105.2551 54.5260)"}
1111
{"index":{"_id": "6"}}
12-
{"region": "Europe", "city": "Amsterdam", "location": "52.347557,4.850312", "location_no_dv": "52.347557,4.850312", "shape": "POINT (4.850312 52.347557 2)", "region_point": "POINT(15.2551 54.5260)"}
12+
{"region": "Europe", "city": "Amsterdam", "location": "52.347557,4.850312", "location_no_dv": "52.347557,4.850312", "geoshape": "POINT (4.850312 52.347557 2)", "shape": "POINT (4.850312 52.347557 2)", "region_point": "POINT(15.2551 54.5260)"}
1313
{"index":{"_id": "7"}}
14-
{"region": "Europe", "city": "Berlin", "location": "52.486701,13.390889", "location_no_dv": "52.486701,13.390889", "shape": "POINT (13.390889 52.486701 34)", "region_point": "POINT(15.2551 54.5260)"}
14+
{"region": "Europe", "city": "Berlin", "location": "52.486701,13.390889", "location_no_dv": "52.486701,13.390889", "geoshape": "POINT (13.390889 52.486701 34)", "shape": "POINT (13.390889 52.486701 34)", "region_point": "POINT(15.2551 54.5260)"}
1515
{"index":{"_id": "8"}}
16-
{"region": "Europe", "city": "Munich", "location": "48.146321,11.537505", "location_no_dv": "48.146321,11.537505", "shape": "POINT (11.537505 48.146321 519)", "region_point": "POINT(15.2551 54.5260)"}
16+
{"region": "Europe", "city": "Munich", "location": "48.146321,11.537505", "location_no_dv": "48.146321,11.537505", "geoshape": "POINT (11.537505 48.146321 519)", "shape": "POINT (11.537505 48.146321 519)", "region_point": "POINT(15.2551 54.5260)"}
1717
{"index":{"_id": "9"}}
18-
{"region": "Europe", "city": "London", "location": "51.510871,-0.121672", "location_no_dv": "51.510871,-0.121672", "shape": "POINT (-0.121672 51.510871 11)", "region_point": "POINT(15.2551 54.5260)"}
18+
{"region": "Europe", "city": "London", "location": "51.510871,-0.121672", "location_no_dv": "51.510871,-0.121672", "geoshape": "POINT (-0.121672 51.510871 11)", "shape": "POINT (-0.121672 51.510871 11)", "region_point": "POINT(15.2551 54.5260)"}
1919
{"index":{"_id": "10"}}
20-
{"region": "Europe", "city": "Paris", "location": "48.845538,2.351773", "location_no_dv": "48.845538,2.351773", "shape": "POINT (2.351773 48.845538 35)", "region_point": "POINT(15.2551 54.5260)"}
20+
{"region": "Europe", "city": "Paris", "location": "48.845538,2.351773", "location_no_dv": "48.845538,2.351773", "geoshape": "POINT (2.351773 48.845538 35)", "shape": "POINT (2.351773 48.845538 35)", "region_point": "POINT(15.2551 54.5260)"}
2121
{"index":{"_id": "11"}}
22-
{"region": "Asia", "city": "Singapore", "location": "1.295868,103.855535", "location_no_dv": "1.295868,103.855535", "shape": "POINT (103.855535 1.295868 15)", "region_point": "POINT(100.6197 34.0479)"}
22+
{"region": "Asia", "city": "Singapore", "location": "1.295868,103.855535", "location_no_dv": "1.295868,103.855535", "geoshape": "POINT (103.855535 1.295868 15)", "shape": "POINT (103.855535 1.295868 15)", "region_point": "POINT(100.6197 34.0479)"}
2323
{"index":{"_id": "12"}}
24-
{"region": "Asia", "city": "Hong Kong", "location": "22.281397,114.183925", "location_no_dv": "22.281397,114.183925", "shape": "POINT (114.183925 22.281397 552)", "region_point": "POINT(100.6197 34.0479)"}
24+
{"region": "Asia", "city": "Hong Kong", "location": "22.281397,114.183925", "location_no_dv": "22.281397,114.183925", "geoshape": "POINT (114.183925 22.281397 552)", "shape": "POINT (114.183925 22.281397 552)", "region_point": "POINT(100.6197 34.0479)"}
2525
{"index":{"_id": "13"}}
26-
{"region": "Asia", "city": "Seoul", "location": "37.509132,127.060851", "location_no_dv": "37.509132,127.060851", "shape": "POINT (127.060851 37.509132 38)", "region_point": "POINT(100.6197 34.0479)"}
26+
{"region": "Asia", "city": "Seoul", "location": "37.509132,127.060851", "location_no_dv": "37.509132,127.060851", "geoshape": "POINT (127.060851 37.509132 38)", "shape": "POINT (127.060851 37.509132 38)", "region_point": "POINT(100.6197 34.0479)"}
2727
{"index":{"_id": "14"}}
28-
{"region": "Asia", "city": "Tokyo", "location": "35.669616,139.76402225", "location_no_dv": "35.669616,139.76402225", "shape": "POINT (139.76402225 35.669616 40)", "region_point": "POINT(100.6197 34.0479)"}
28+
{"region": "Asia", "city": "Tokyo", "location": "35.669616,139.76402225", "location_no_dv": "35.669616,139.76402225", "geoshape": "POINT (139.76402225 35.669616 40)", "shape": "POINT (139.76402225 35.669616 40)", "region_point": "POINT(100.6197 34.0479)"}
2929
{"index":{"_id": "15"}}
30-
{"region": "Asia", "city": "Sydney", "location": "-33.863385,151.208629", "location_no_dv": "-33.863385,151.208629", "shape": "POINT (151.208629 -33.863385 100)", "region_point": "POINT(100.6197 34.0479)"}
30+
{"region": "Asia", "city": "Sydney", "location": "-33.863385,151.208629", "location_no_dv": "-33.863385,151.208629", "geoshape": "POINT (151.208629 -33.863385 100)", "shape": "POINT (151.208629 -33.863385 100)", "region_point": "POINT(100.6197 34.0479)"}
3131

3232

3333

0 commit comments

Comments
 (0)