Skip to content

Commit d5a43c3

Browse files
authored
SQL: Add ST_Z function (#41772)
Adds support for the ST_Z function that returns the altitude of the first point in a shape. Relates to #29872
1 parent 7b8ab09 commit d5a43c3

File tree

14 files changed

+170
-74
lines changed

14 files changed

+170
-74
lines changed

docs/reference/sql/functions/geo.asciidoc

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ST_AsWKT(geometry<1>)
2424

2525
.Description:
2626

27-
Returns the WKT representation of the `geometry`. The return type is string.
27+
Returns the WKT representation of the `geometry`.
2828

2929
["source","sql",subs="attributes,macros"]
3030
--------------------------------------------------
@@ -43,13 +43,13 @@ ST_WKTToSQL(string<1>)
4343

4444
*Input*:
4545

46-
<1> string geometry
46+
<1> string WKT representation of geometry
4747

48-
*Output*: WKT string
48+
*Output*: geometry
4949

5050
.Description:
5151

52-
Returns the geometry from WKT representation. The return type is geometry.
52+
Returns the geometry from WKT representation.
5353

5454
["source","sql",subs="attributes,macros"]
5555
--------------------------------------------------
@@ -77,8 +77,6 @@ ST_GeometryType(geometry<1>)
7777

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

80-
The return type is string.
81-
8280
["source","sql",subs="attributes,macros"]
8381
--------------------------------------------------
8482
include-tagged::{sql-specs}/docs/geo.csv-spec[geometrytype]
@@ -102,7 +100,6 @@ ST_X(geometry<1>)
102100
.Description:
103101

104102
Returns the longitude of the first point in the geometry.
105-
The return type is double.
106103

107104
["source","sql",subs="attributes,macros"]
108105
--------------------------------------------------
@@ -127,13 +124,36 @@ ST_Y(geometry<1>)
127124
.Description:
128125

129126
Returns the the latitude of the first point in the geometry.
130-
The return type is double.
131127

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

133+
[[sql-functions-geo-st-z]]
134+
===== `ST_Z`
135+
136+
.Synopsis:
137+
[source, sql]
138+
--------------------------------------------------
139+
ST_Z(geometry<1>)
140+
--------------------------------------------------
141+
142+
*Input*:
143+
144+
<1> geometry
145+
146+
*Output*: double
147+
148+
.Description:
149+
150+
Returns the altitude of the first point in the geometry.
151+
152+
["source","sql",subs="attributes,macros"]
153+
--------------------------------------------------
154+
include-tagged::{sql-specs}/docs/geo.csv-spec[z]
155+
--------------------------------------------------
156+
137157
[[sql-functions-geo-st-distance]]
138158
===== `ST_Distance`
139159

@@ -152,7 +172,7 @@ ST_Distance(geometry<1>, geometry<2>)
152172

153173
.Description:
154174

155-
Returns the distance between geometries in meters. Both geometries have to be points. The return type is double.
175+
Returns the distance between geometries in meters. Both geometries have to be points.
156176

157177
["source","sql",subs="attributes,macros"]
158178
--------------------------------------------------

docs/reference/sql/functions/index.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
** <<sql-functions-geo-st-wkt-to-sql>>
144144
** <<sql-functions-geo-st-x>>
145145
** <<sql-functions-geo-st-y>>
146+
** <<sql-functions-geo-st-z>>
146147
* <<sql-functions-system>>
147148
** <<sql-functions-system-database>>
148149
** <<sql-functions-system-user>>

x-pack/plugin/sql/qa/src/main/resources/command.csv-spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ ST_GEOMFROMTEXT |SCALAR
142142
ST_WKTTOSQL |SCALAR
143143
ST_X |SCALAR
144144
ST_Y |SCALAR
145+
ST_Z |SCALAR
145146
SCORE |SCORE
146147
;
147148

x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ ST_GEOMFROMTEXT |SCALAR
319319
ST_WKTTOSQL |SCALAR
320320
ST_X |SCALAR
321321
ST_Y |SCALAR
322+
ST_Z |SCALAR
322323
SCORE |SCORE
323324
// end::showFunctions
324325
;

x-pack/plugin/sql/qa/src/main/resources/docs/geo.csv-spec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ SELECT ST_Y(ST_WKTToSQL('POINT (10 20)')) y;
6868
20.0
6969
// end::y
7070
;
71+
72+
selectZ
73+
// tag::z
74+
SELECT ST_Z(ST_WKTToSQL('POINT (10 20 30)')) z;
75+
76+
z:d
77+
30.0
78+
// end::z
79+
;
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)", "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"}, "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]}, "region_point": "POINT(-105.2551 54.5260)"}
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)"}
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)", "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", "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)", "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", "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)", "region_point": "POINT(-105.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(15.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(15.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(15.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(15.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(15.2551 54.5260)"}
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)"}
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)", "region_point": "POINT(100.6197 34.0479)"}
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)"}
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)", "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", "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)", "region_point": "POINT(100.6197 34.0479)"}
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)"}
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)", "region_point": "POINT(100.6197 34.0479)"}
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)"}
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)", "region_point": "POINT(100.6197 34.0479)"}
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)"}
3131

3232

3333

0 commit comments

Comments
 (0)