Skip to content

[9.2] Fix ST_DISTANCE handling of invalid geometry literals that fold to null (#140116) (#140265)#140276

Merged
elasticsearchmachine merged 1 commit intoelastic:9.2from
craigtaverner:9.2_geometry_literal_npe
Jan 7, 2026
Merged

[9.2] Fix ST_DISTANCE handling of invalid geometry literals that fold to null (#140116) (#140265)#140276
elasticsearchmachine merged 1 commit intoelastic:9.2from
craigtaverner:9.2_geometry_literal_npe

Conversation

@craigtaverner
Copy link
Contributor

Manual backport of #140265

…ll (elastic#140116) (elastic#140265)

Occasionally on serverless we see a NullPointerException in parsing a geometry literal within ST_DISTANCE functions. This turned out to be hard to reproduce since we cannot see the original query causing this problem. It has been reported in elastic#138594, including a full stack track confirming that it occurs during planning, while folding literals.

It turned out to be reproducible with a query like:

```
ROW point = MV_SLICE(["POINT(0)"], 0, 0)::geo_point
| EVAL distance = ST_DISTANCE(point, point)
```

Here the WKT is invalid, and the fold over the MV_SLICE would return literal `null` values, since the inner TO_GEOPOINT function was throwing exceptions (since the WKT was invalid). It turned out that MvSlice was using EvaluatorMapper.fold for folding the children, which returns literal java `null` values, and any function using these values needs to also handle literal nulls. So, `fold()` is expected to explicitly return null values when input is null, and the implementation of fold in StDistance did not do this.

This PR now covers all descendents of BinarySpatialFunction:
* ST_DISTANCE
* ST_INTERSECTS
* ST_DISJOINT
* ST_CONTAINS
* ST_WITHIN
@craigtaverner craigtaverner added >bug :Analytics/Geo Indexing, search aggregations of geo points and shapes backport Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Analytics/ES|QL AKA ESQL branch:9.2 labels Jan 7, 2026
@elasticsearchmachine elasticsearchmachine merged commit dfc5c38 into elastic:9.2 Jan 7, 2026
35 checks passed
@craigtaverner craigtaverner deleted the 9.2_geometry_literal_npe branch January 7, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL :Analytics/Geo Indexing, search aggregations of geo points and shapes auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.5

2 participants