Skip to content

Commit 6cd7e25

Browse files
committed
Remove support for geogrid in ST_INTERSECTS
1 parent 00ad3ce commit 6cd7e25

File tree

19 files changed

+105
-864
lines changed

19 files changed

+105
-864
lines changed

docs/reference/query-languages/esql/_snippets/functions/parameters/st_disjoint.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/st_intersects.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/st_disjoint.md

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/st_intersects.md

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/st_disjoint.json

Lines changed: 16 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/st_intersects.json

Lines changed: 16 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -255,33 +255,6 @@ count:long | centroid:geo_point | geohashString:keywo
255255
2 | POINT (16.706149326637387 32.37822346854955) | sm | POLYGON((11.25 28.125, 22.5 28.125, 22.5 33.75, 11.25 33.75, 11.25 28.125))
256256
;
257257

258-
gridGeohashDocsFromCell
259-
required_capability: spatial_grid_types
260-
261-
FROM airports
262-
| WHERE ST_INTERSECTS(location, TO_GEOHASH("u1"))
263-
| STATS
264-
count = COUNT(*),
265-
centroid = ST_CENTROID_AGG(location)
266-
;
267-
268-
count:long | centroid:geo_point
269-
8 | POINT (6.351574736181647 51.8981519783847)
270-
;
271-
272-
gridGeohashLiteralFromCell
273-
required_capability: spatial_grid_types
274-
275-
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (6.351574736181647 51.8981519783847)", "POINT (5.268637698941997 42.747250193330856)"]
276-
| EVAL location = TO_GEOPOINT(location)
277-
| MV_EXPAND location
278-
| WHERE ST_INTERSECTS(location, "u1"::geohash)
279-
;
280-
281-
location:geo_point
282-
POINT (6.351574736181647 51.8981519783847)
283-
;
284-
285258
gridGeohashStatsByWhereUK
286259
required_capability: spatial_grid_types
287260

@@ -590,33 +563,6 @@ count:long | centroid:geo_point | geotileString:keywor
590563
79 | POINT (24.516750878736943 23.93036561181085) | 3/4/3 | POLYGON((0.0 0.0, 45.0 0.0, 45.0 40.979898069620134, 0.0 40.979898069620134, 0.0 0.0))
591564
;
592565

593-
gridGeotileDocsFromCell
594-
required_capability: spatial_grid_types
595-
596-
FROM airports
597-
| WHERE ST_INTERSECTS(location, TO_GEOTILE("3/4/3"))
598-
| STATS
599-
count = COUNT(*),
600-
centroid = ST_CENTROID_AGG(location)
601-
;
602-
603-
count:long | centroid:geo_point
604-
79 | POINT (24.516750878736943 23.93036561181085)
605-
;
606-
607-
gridGeotileLiteralFromCell
608-
required_capability: spatial_grid_types
609-
610-
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (24.516750878736943 23.93036561181085)", "POINT (5.268637698941997 42.747250193330856)"]
611-
| EVAL location = TO_GEOPOINT(location)
612-
| MV_EXPAND location
613-
| WHERE ST_INTERSECTS(location, "3/4/3"::geotile)
614-
;
615-
616-
location:geo_point
617-
POINT (24.516750878736943 23.93036561181085)
618-
;
619-
620566
gridGeotileStatsByWhereUK
621567
required_capability: spatial_grid_types
622568

@@ -994,34 +940,6 @@ POINT (13.1442589810713 32.6691695504993) | 813fbffffffffff | 813fbffffffffff
994940
POINT (118.12696884672 24.537192570557) | 8141bffffffffff | null | POLYGON ((121.34751445935747 26.200276060455465, 120.50339385995798 29.892985338693542, 116.26130043917948 31.68090796798786, 112.74092235558841 29.367231998154967, 113.70376749169584 25.199133186716526, 117.99047716641066 23.5089519597363, 119.64146543031175 24.728661050965922, 121.34751445935747 26.200276060455465))
995941
;
996942

997-
gridGeohexDocsFromCell
998-
required_capability: spatial_grid_types
999-
1000-
FROM airports
1001-
| WHERE ST_INTERSECTS(location, TO_GEOHEX("81397ffffffffff"))
1002-
| STATS
1003-
count = COUNT(*),
1004-
centroid = ST_CENTROID_AGG(location)
1005-
;
1006-
1007-
count:long | centroid:geo_point
1008-
7 | POINT (2.475211258445467 41.32352174592337)
1009-
;
1010-
1011-
gridGeohexLiteralFromCell
1012-
required_capability: spatial_grid_types
1013-
1014-
ROW location = ["POINT (6.360728044651057 47.94084087577894)", "POINT (2.475211258445467 41.32352174592337)", "POINT (5.268637698941997 42.747250193330856)"]
1015-
| EVAL location = TO_GEOPOINT(location)
1016-
| MV_EXPAND location
1017-
| WHERE ST_INTERSECTS(location, "81397ffffffffff"::geohex)
1018-
;
1019-
1020-
location:geo_point
1021-
POINT (2.475211258445467 41.32352174592337)
1022-
POINT (5.268637698941997 42.747250193330856)
1023-
;
1024-
1025943
gridGeohexStatsByWhereUK
1026944
required_capability: spatial_grid_types
1027945

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/spatial/BinarySpatialFunction.java

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.io.IOException;
2929
import java.util.Objects;
30-
import java.util.function.Predicate;
3130

3231
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
3332
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
@@ -56,17 +55,15 @@ protected BinarySpatialFunction(
5655
Expression right,
5756
boolean leftDocValues,
5857
boolean rightDocValues,
59-
boolean pointsOnly,
60-
boolean supportsGrid
58+
boolean pointsOnly
6159
) {
6260
super(source, left, right);
6361
this.leftDocValues = leftDocValues;
6462
this.rightDocValues = rightDocValues;
65-
this.spatialTypeResolver = new SpatialTypeResolver(this, pointsOnly, supportsGrid);
63+
this.spatialTypeResolver = new SpatialTypeResolver(this, pointsOnly);
6664
}
6765

68-
protected BinarySpatialFunction(StreamInput in, boolean leftDocValues, boolean rightDocValues, boolean pointsOnly, boolean supportsGrid)
69-
throws IOException {
66+
protected BinarySpatialFunction(StreamInput in, boolean leftDocValues, boolean rightDocValues, boolean pointsOnly) throws IOException {
7067
// The doc-values fields are only used on data nodes local planning, and therefor never serialized
7168
this(
7269
in.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_SOURCE_FUNCTIONS_WARNINGS)
@@ -76,8 +73,7 @@ protected BinarySpatialFunction(StreamInput in, boolean leftDocValues, boolean r
7673
in.readNamedWriteable(Expression.class),
7774
leftDocValues,
7875
rightDocValues,
79-
pointsOnly,
80-
supportsGrid
76+
pointsOnly
8177
);
8278
}
8379

@@ -123,12 +119,10 @@ protected TypeResolution resolveType() {
123119
static class SpatialTypeResolver {
124120
private final SpatialEvaluatorFactory.SpatialSourceResolution supplier;
125121
private final boolean pointsOnly;
126-
private final boolean supportsGrid;
127122

128-
SpatialTypeResolver(SpatialEvaluatorFactory.SpatialSourceResolution supplier, boolean pointsOnly, boolean supportsGrid) {
123+
SpatialTypeResolver(SpatialEvaluatorFactory.SpatialSourceResolution supplier, boolean pointsOnly) {
129124
this.supplier = supplier;
130125
this.pointsOnly = pointsOnly;
131-
this.supportsGrid = supportsGrid;
132126
}
133127

134128
public Expression left() {
@@ -153,16 +147,10 @@ protected TypeResolution resolveType() {
153147
}
154148
}
155149

156-
protected Expression.TypeResolution isCompatibleSpatial(Expression e, TypeResolutions.ParamOrdinal paramOrd) {
150+
protected Expression.TypeResolution isSpatial(Expression e, TypeResolutions.ParamOrdinal paramOrd) {
157151
return pointsOnly
158152
? EsqlTypeResolutions.isSpatialPoint(e, sourceText(), paramOrd)
159-
: (supportsGrid
160-
? EsqlTypeResolutions.isSpatialOrGrid(e, sourceText(), paramOrd)
161-
: EsqlTypeResolutions.isSpatial(e, sourceText(), paramOrd));
162-
}
163-
164-
protected Expression.TypeResolution isGeoPoint(Expression e, TypeResolutions.ParamOrdinal paramOrd) {
165-
return isType(e, GEO_POINT::equals, sourceText(), paramOrd, GEO_POINT.typeName());
153+
: EsqlTypeResolutions.isSpatial(e, sourceText(), paramOrd);
166154
}
167155

168156
private TypeResolution resolveType(
@@ -171,8 +159,8 @@ private TypeResolution resolveType(
171159
TypeResolutions.ParamOrdinal leftOrdinal,
172160
TypeResolutions.ParamOrdinal rightOrdinal
173161
) {
174-
TypeResolution leftResolution = isCompatibleSpatial(leftExpression, leftOrdinal);
175-
TypeResolution rightResolution = isCompatibleSpatial(rightExpression, rightOrdinal);
162+
TypeResolution leftResolution = isSpatial(leftExpression, leftOrdinal);
163+
TypeResolution rightResolution = isSpatial(rightExpression, rightOrdinal);
176164
if (leftResolution.resolved()) {
177165
return resolveType(leftExpression, rightExpression, rightOrdinal);
178166
} else if (rightResolution.resolved()) {
@@ -188,16 +176,9 @@ protected TypeResolution resolveType(
188176
TypeResolutions.ParamOrdinal otherParamOrdinal
189177
) {
190178
if (isNull(spatialExpression.dataType())) {
191-
return isCompatibleSpatial(otherExpression, otherParamOrdinal);
179+
return isSpatial(otherExpression, otherParamOrdinal);
192180
}
193181
TypeResolution resolution = isSameSpatialType(spatialExpression.dataType(), otherExpression, sourceText(), otherParamOrdinal);
194-
// TODO Remove these grid checks once we support geo_shape relation to geoGrid
195-
if (resolution.resolved() && DataType.isGeoGrid(spatialExpression.dataType())) {
196-
resolution = isGeoPoint(otherExpression, otherParamOrdinal);
197-
}
198-
if (resolution.resolved() && DataType.isGeoGrid(otherExpression.dataType())) {
199-
resolution = isGeoPoint(spatialExpression, otherParamOrdinal == FIRST ? SECOND : FIRST);
200-
}
201182
if (resolution.unresolved()) {
202183
return resolution;
203184
}
@@ -211,12 +192,15 @@ protected TypeResolution isSameSpatialType(
211192
String operationName,
212193
TypeResolutions.ParamOrdinal paramOrd
213194
) {
214-
Predicate<DataType> isSpatialType = pointsOnly
215-
? dt -> dt == spatialDataType
216-
: (supportsGrid
217-
? dt -> DataType.isSpatialOrGrid(dt) && spatialCRSCompatible(spatialDataType, dt)
218-
: dt -> DataType.isSpatial(dt) && spatialCRSCompatible(spatialDataType, dt));
219-
return isType(expression, isSpatialType, operationName, paramOrd, compatibleTypeNames(spatialDataType));
195+
return pointsOnly
196+
? isType(expression, dt -> dt == spatialDataType, operationName, paramOrd, compatibleTypeNames(spatialDataType))
197+
: isType(
198+
expression,
199+
dt -> DataType.isSpatial(dt) && spatialCRSCompatible(spatialDataType, dt),
200+
operationName,
201+
paramOrd,
202+
compatibleTypeNames(spatialDataType)
203+
);
220204
}
221205
}
222206

@@ -264,7 +248,7 @@ public enum SpatialCrsType {
264248

265249
public static SpatialCrsType fromDataType(DataType dataType) {
266250
return DataType.isSpatialGeo(dataType) ? SpatialCrsType.GEO
267-
: DataType.isSpatialOrGrid(dataType) ? SpatialCrsType.CARTESIAN
251+
: DataType.isSpatial(dataType) ? SpatialCrsType.CARTESIAN
268252
: SpatialCrsType.UNSPECIFIED;
269253
}
270254
}
@@ -294,8 +278,8 @@ public TranslationAware.Translatable translatable(LucenePushdownPredicates pushd
294278
// The use of foldable here instead of SpatialEvaluatorFieldKey.isConstant is intentional to match the behavior of the
295279
// Lucene pushdown code in EsqlTranslationHandler::SpatialRelatesTranslator
296280
// We could enhance both places to support ReferenceAttributes that refer to constants, but that is a larger change
297-
return isPushableSpatialAttribute(left(), pushdownPredicates) && isPushableLiteralAttribute(right())
298-
|| isPushableSpatialAttribute(right(), pushdownPredicates) && isPushableLiteralAttribute(left())
281+
return isPushableSpatialAttribute(left(), pushdownPredicates) && right().foldable()
282+
|| isPushableSpatialAttribute(right(), pushdownPredicates) && left().foldable()
299283
? TranslationAware.Translatable.YES
300284
: TranslationAware.Translatable.NO;
301285

@@ -304,9 +288,4 @@ public TranslationAware.Translatable translatable(LucenePushdownPredicates pushd
304288
private static boolean isPushableSpatialAttribute(Expression exp, LucenePushdownPredicates p) {
305289
return exp instanceof FieldAttribute fa && DataType.isSpatial(fa.dataType()) && fa.getExactInfo().hasExact() && p.isIndexed(fa);
306290
}
307-
308-
private static boolean isPushableLiteralAttribute(Expression exp) {
309-
// TODO: Support pushdown of geo-grid queries where the constant is a geo-grid-id literal
310-
return DataType.isSpatial(exp.dataType()) && exp.foldable();
311-
}
312291
}

0 commit comments

Comments
 (0)