Skip to content

Commit 49385eb

Browse files
committed
Add ESQL Capability and reduce test flakiness
1 parent 0726a1d commit 49385eb

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/spatial-grid.csv-spec

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
###############################################
44

55
geohashLiteral
6+
required_capability: spatial_grid
7+
68
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
79
| EVAL geohash4 = ST_GEOHASH(location, 4),
810
geohash3 = ST_GEOHASH(location, 3),
@@ -15,6 +17,8 @@ POINT(12.6493508684508 55.6285017221528) | u3bu | u3b | u3 | u
1517
;
1618

1719
geohashLiteralMv
20+
required_capability: spatial_grid
21+
1822
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)"), precision = [1,2,3,4,5]
1923
| MV_EXPAND precision
2024
| EVAL geohash = ST_GEOHASH(location, precision)
@@ -29,6 +33,8 @@ POINT (12.6493508684508 55.6285017221528) | 5 | u3bur
2933
;
3034

3135
geohashField
36+
required_capability: spatial_grid
37+
3238
FROM airports
3339
| WHERE abbrev == "CPH"
3440
| EVAL geohash = ST_GEOHASH(location, 7)
@@ -41,6 +47,8 @@ u3buryf | CPH | Copenhagen | POINT (12.6493508684508 55.62850
4147

4248
gridGeohashStatsBy
4349
// tag::st_geohash-grid[]
50+
required_capability: spatial_grid
51+
4452
FROM airports
4553
| EVAL geohash = ST_GEOHASH(location, 1)
4654
| STATS
@@ -75,6 +83,8 @@ count:long | centroid:geo_point | geohash:keyword
7583
;
7684

7785
gridGeohashStatsByBounds
86+
required_capability: spatial_grid
87+
7888
FROM airports
7989
| EVAL geohash = ST_GEOHASH(location, 2, TO_GEOSHAPE("BBOX(0, 12, 60, 30)"))
8090
| WHERE geohash IS NOT NULL
@@ -95,6 +105,8 @@ count:long | centroid:geo_point | geohash:keyword
95105
;
96106

97107
gridGeohashStatsByWhereUK
108+
required_capability: spatial_grid
109+
98110
FROM airports
99111
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
100112
| EVAL geohash = ST_GEOHASH(location, 2)
@@ -111,6 +123,8 @@ count:long | centroid:geo_point | geohash:keyword
111123
;
112124

113125
gridGeohashStatsByBoundsUK
126+
required_capability: spatial_grid
127+
114128
FROM airports
115129
| EVAL bounds = ST_ENVELOPE(TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
116130
| EVAL geohash = ST_GEOHASH(location, 2, bounds)
@@ -129,6 +143,8 @@ count:long | centroid:geo_point | geohash:keyword
129143
;
130144

131145
gridGeohashInStatsBy
146+
required_capability: spatial_grid
147+
132148
FROM airports
133149
| STATS
134150
count = COUNT(location),
@@ -153,6 +169,8 @@ count:long | centroid:geo_point
153169
;
154170

155171
gridGeohashInStatsByWhereUK
172+
required_capability: spatial_grid
173+
156174
FROM airports
157175
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
158176
| STATS
@@ -173,6 +191,8 @@ count:long | centroid:geo_point
173191
###############################################
174192

175193
geotileLiteral
194+
required_capability: spatial_grid
195+
176196
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
177197
| EVAL geotile4 = ST_GEOTILE(location, 4),
178198
geotile3 = ST_GEOTILE(location, 3),
@@ -185,6 +205,8 @@ POINT (12.6493508684508 55.6285017221528) | 4/8/5 | 3/4/2
185205
;
186206

187207
geotileLiteralMv
208+
required_capability: spatial_grid
209+
188210
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)"), precision = [1,2,3,4,5]
189211
| MV_EXPAND precision
190212
| EVAL geotile = ST_GEOTILE(location, precision)
@@ -199,6 +221,8 @@ POINT (12.6493508684508 55.6285017221528) | 5 | 5/17/10
199221
;
200222

201223
geotileField
224+
required_capability: spatial_grid
225+
202226
FROM airports
203227
| WHERE abbrev == "CPH"
204228
| EVAL geotile = ST_GEOTILE(location, 7)
@@ -211,6 +235,8 @@ geotile:keyword | abbrev:keyword | name:text | location:geo_point
211235

212236
gridGeotileStatsBy
213237
// tag::st_geotile-grid[]
238+
required_capability: spatial_grid
239+
214240
FROM airports
215241
| EVAL geotile = ST_GEOTILE(location, 2)
216242
| STATS
@@ -238,6 +264,8 @@ count:long | centroid:geo_point | geotile:keyword
238264
;
239265

240266
gridGeotileStatsByBounds
267+
required_capability: spatial_grid
268+
241269
FROM airports
242270
| EVAL geotile = ST_GEOTILE(location, 3, TO_GEOSHAPE("BBOX(0, 12, 60, 30)"))
243271
| WHERE geotile IS NOT NULL
@@ -254,6 +282,8 @@ count:long | centroid:geo_point | geotile:keyword
254282
;
255283

256284
gridGeotileStatsByWhereUK
285+
required_capability: spatial_grid
286+
257287
FROM airports
258288
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
259289
| EVAL geotile = ST_GEOTILE(location, 4)
@@ -270,6 +300,8 @@ count:long | centroid:geo_point | geotile:keyword
270300
;
271301

272302
gridGeotileStatsByBoundsUK
303+
required_capability: spatial_grid
304+
273305
FROM airports
274306
| EVAL bounds = ST_ENVELOPE(TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
275307
| EVAL geotile = ST_GEOTILE(location, 2, bounds)
@@ -287,6 +319,8 @@ count:long | centroid:geo_point | geotile:keyword
287319
;
288320

289321
gridGeotileInStatsBy
322+
required_capability: spatial_grid
323+
290324
FROM airports
291325
| STATS
292326
count = COUNT(location),
@@ -305,6 +339,8 @@ count:long | centroid:geo_point
305339
;
306340

307341
gridGeotileInStatsByWhereUK
342+
required_capability: spatial_grid
343+
308344
FROM airports
309345
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
310346
| STATS
@@ -324,6 +360,8 @@ count:long | centroid:geo_point
324360
###############################################
325361

326362
geohexLiteral
363+
required_capability: spatial_grid
364+
327365
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
328366
| EVAL geohex4 = ST_GEOHEX(location, 4),
329367
geohex3 = ST_GEOHEX(location, 3),
@@ -336,6 +374,8 @@ POINT (12.6493508684508 55.6285017221528) | 841f059ffffffff | 831f05fffffffff |
336374
;
337375

338376
geohexLiteralMv
377+
required_capability: spatial_grid
378+
339379
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)"), precision = [1,2,3,4,5]
340380
| MV_EXPAND precision
341381
| EVAL geohex = ST_GEOHEX(location, precision)
@@ -350,6 +390,8 @@ POINT (12.6493508684508 55.6285017221528) | 5 | 851f0583fffffff
350390
;
351391

352392
geohexField
393+
required_capability: spatial_grid
394+
353395
FROM airports
354396
| WHERE abbrev == "CPH"
355397
| EVAL geohex = ST_GEOHEX(location, 7)
@@ -362,6 +404,8 @@ geohex:keyword | abbrev:keyword | name:text | location:geo_point
362404

363405
gridGeohexStatsBy
364406
// tag::st_geohex-grid[]
407+
required_capability: spatial_grid
408+
365409
FROM airports
366410
| EVAL geohex = ST_GEOHEX(location, 1)
367411
| STATS
@@ -390,6 +434,8 @@ count:long | centroid:geo_point | geohex:keyword
390434
;
391435

392436
gridGeohexStatsByBounds
437+
required_capability: spatial_grid
438+
393439
FROM airports
394440
| EVAL geohex = ST_GEOHEX(location, 1, TO_GEOSHAPE("BBOX(0, 12, 60, 30)"))
395441
| WHERE geohex IS NOT NULL
@@ -413,6 +459,8 @@ count:long | centroid:geo_point | geohex:keyword
413459
;
414460

415461
gridGeohexStatsByWhereUK
462+
required_capability: spatial_grid
463+
416464
FROM airports
417465
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
418466
| EVAL geohex = ST_GEOHEX(location, 1)
@@ -431,6 +479,8 @@ count:long | centroid:geo_point | geohex:keyword
431479
;
432480

433481
gridGeohexStatsByBoundsUK
482+
required_capability: spatial_grid
483+
434484
FROM airports
435485
| EVAL bounds = ST_ENVELOPE(TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
436486
| EVAL geohex = ST_GEOHEX(location, 2, bounds)
@@ -455,44 +505,41 @@ count:long | centroid:geo_point | geohex:keyword
455505
1 | POINT (-0.16296171583235264 51.1557567352429) | 82194ffffffffff
456506
;
457507

458-
gridGeohexInStatsBy
508+
gridGeohexInStatsByBounds
509+
required_capability: spatial_grid
510+
459511
FROM airports
460512
| STATS
461513
count = COUNT(location),
462514
centroid = ST_CENTROID_AGG(location)
463-
BY ST_GEOHEX(location, 1)
515+
BY ST_GEOHEX(location, 2, TO_GEOSHAPE("BBOX(0, 12, 60, 30)"))
516+
| WHERE count > 3
464517
| SORT count DESC
465518
| KEEP count, centroid
466519
| LIMIT 10
467520
;
468521

469-
count:long | centroid:geo_point
470-
22 | POINT (7.250850197689777 48.21363834643059)
471-
18 | POINT (-80.64959161449224 40.04119813675061)
472-
17 | POINT (-0.7606179875266903 52.86413913565304)
473-
13 | POINT (22.53157936179867 41.98255742864254)
474-
13 | POINT (78.30096947387435 26.073904778951636)
475-
12 | POINT (-100.30120467301458 20.114154297625646)
476-
12 | POINT (-76.39781514415517 45.16300531569868)
477-
11 | POINT (-99.4237939513881 27.100012352774765)
478-
11 | POINT (-83.42379064553164 33.18388901439241)
479-
11 | POINT (18.037187419831753 48.66540593306788)
522+
count:long | centroid:geo_point
523+
850 | POINT (-0.347950274354833 23.284863485719132)
524+
6 | POINT (5.582276992499828 50.72238312335685)
525+
5 | POINT (8.6918301936239 45.19817395694554)
480526
;
481527

482528
gridGeohexInStatsByWhereUK
529+
required_capability: spatial_grid
530+
483531
FROM airports
484532
| WHERE ST_INTERSECTS(location, TO_GEOSHAPE("POLYGON((1.2305 60.8449, -1.582 61.6899, -10.7227 58.4017, -7.1191 55.3291, -7.9102 54.2139, -5.4492 54.0078, -5.2734 52.3756, -7.8223 49.6676, -5.0977 49.2678, 0.9668 50.5134, 2.5488 52.1065, 2.6367 54.0078, -0.9668 56.4625, 1.2305 60.8449))"))
485533
| STATS
486534
count = COUNT(location),
487535
centroid = ST_CENTROID_AGG(location)
488536
BY ST_GEOHEX(location, 1)
537+
| WHERE count > 1
489538
| KEEP count, centroid
490539
| SORT count DESC
491540
;
492541

493542
count:long | centroid:geo_point
494543
13 | POINT (-2.283508819169723 53.28242553254733)
495544
2 | POINT (-3.482485176064074 58.24696456314996)
496-
1 | POINT (-6.216169511899352 54.66155751608312)
497-
1 | POINT (-1.2880607228726149 59.87668995279819)
498545
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ public enum Cap {
364364
*/
365365
ST_ENVELOPE,
366366

367+
/**
368+
* Support ST_GEOHASH, ST_GEOTILE and ST_GEOHEX functions
369+
*/
370+
SPATIAL_GRID,
371+
367372
/**
368373
* Fix to GROK and DISSECT that allows extracting attributes with the same name as the input
369374
* https://github.com/elastic/elasticsearch/issues/110184

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ setup:
9393
- gt: {esql.functions.to_long: $functions_to_long}
9494
- match: {esql.functions.coalesce: $functions_coalesce}
9595
# Testing for the entire function set isn't feasbile, so we just check that we return the correct count as an approximation.
96-
- length: {esql.functions: 134} # check the "sister" test below for a likely update to the same esql.functions length check
96+
- length: {esql.functions: 137} # check the "sister" test below for a likely update to the same esql.functions length check
9797

9898
---
9999
"Basic ESQL usage output (telemetry) non-snapshot version":
@@ -164,4 +164,4 @@ setup:
164164
- match: {esql.functions.cos: $functions_cos}
165165
- gt: {esql.functions.to_long: $functions_to_long}
166166
- match: {esql.functions.coalesce: $functions_coalesce}
167-
- length: {esql.functions: 131} # check the "sister" test above for a likely update to the same esql.functions length check
167+
- length: {esql.functions: 134} # check the "sister" test above for a likely update to the same esql.functions length check

0 commit comments

Comments
 (0)