Skip to content

Commit ff30815

Browse files
Support multi-valued fields in compute engine for ST_DISTANCE (#114836) (#114860)
In #112063 we added support for multivalued fields to the compute engine for ST_INTERSECTS and relatives, but not for ST_DISTANCE. In #114729 it was discovered that, at least for the common case of a field and a constant, this support was not needed due to ST_DISTANCE being re-written to ST_INTERSECTS. However, for many other cases, like ST_DISTANCE used on the coordinator node, or between two fields, this lack of support would result in null values. This PR fixes those cases, making sure ST_DISTANCE uses the Block-Builder approach similar to what was done for ST_INTERSECTS et al.
1 parent 17022fd commit ff30815

File tree

17 files changed

+455
-519
lines changed

17 files changed

+455
-519
lines changed

docs/changelog/114836.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 114836
2+
summary: Support multi-valued fields in compute engine for ST_DISTANCE
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 112910

x-pack/plugin/esql/qa/testFixtures/src/main/resources/mapping-multivalue_points.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
"centroid": {
1313
"type": "geo_point"
1414
},
15+
"lk": {
16+
"type": "keyword"
17+
},
1518
"location": {
1619
"type": "geo_point"
1720
},
1821
"subset": {
1922
"type": "geo_point"
23+
},
24+
"disjoint": {
25+
"type": "geo_point"
2026
}
2127
}
2228
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
id:l, intersects:boolean, within:boolean, centroid:geo_point, location:geo_point, subset:geo_point
2-
0, true, true, "POINT(0.0 5.0)", ["POINT(5 5)", "POINT(-5 5)"], "POINT(5 5)"
3-
1, true, true, "POINT(0.5 0.5)", ["POINT(0 1)","POINT(1 0)"], "POINT(0 1)"
4-
2, true, true, "POINT(9.0 9.0)", "POINT(9 9)", "POINT(9 9)"
5-
3, true, true, "POINT(0.0 0.0)", ["POINT(-9 -9)","POINT(9 9)"], "POINT(-9 -9)"
6-
4, true, false, "POINT(10.0 10.0)", ["POINT(5 5)", "POINT(15 15)"], "POINT(5 5)"
7-
5, true, false, "POINT(5.5 5.5)", ["POINT(0 0)","POINT(11 11)"], "POINT(0 0)"
8-
6, true, false, "POINT(0.0 -5.0)", ["POINT(-9 -19)","POINT(9 9)"], "POINT(-9 -19)"
9-
7, false, false, "POINT(10.0 10.0)", ["POINT(5 15)", "POINT(15 5)"], "POINT(5 15)"
10-
8, false, false, "POINT(5.5 5.5)", ["POINT(0 11)","POINT(11 0)"], "POINT(0 11)"
11-
9, false, false, "POINT(19.0 9.0)", "POINT(19 9)", "POINT(19 9)"
12-
10, false, false, "POINT(5.0 -5.0)", ["POINT(-9 -19)","POINT(19 9)"], "POINT(-9 -19)"
13-
11, true, false, "POINT(0.0 0.0)", ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 55)"]
14-
12, true, false, "POINT(0.0 0.0)", ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 54)"]
1+
id:l, intersects:boolean, within:boolean, centroid:geo_point, lk:keyword, location:geo_point, subset:geo_point, disjoint:geo_point
2+
0, true, true, "POINT(0.0 5.0)", ["POINT(5 5)", "POINT(-5 5)"], ["POINT(5 5)", "POINT(-5 5)"], "POINT(5 5)", ["POINT(55 55)", "POINT(65 65)"]
3+
1, true, true, "POINT(0.5 0.5)", ["POINT(0 1)","POINT(1 0)"], ["POINT(0 1)","POINT(1 0)"], "POINT(0 1)", ["POINT(55 55)", "POINT(65 65)"]
4+
2, true, true, "POINT(9.0 9.0)", "POINT(9 9)", "POINT(9 9)", "POINT(9 9)", ["POINT(55 55)", "POINT(65 65)"]
5+
3, true, true, "POINT(0.0 0.0)", ["POINT(-9 -9)","POINT(9 9)"], ["POINT(-9 -9)","POINT(9 9)"], "POINT(-9 -9)", ["POINT(55 55)", "POINT(65 65)"]
6+
4, true, false, "POINT(10.0 10.0)", ["POINT(5 5)", "POINT(15 15)"], ["POINT(5 5)", "POINT(15 15)"], "POINT(5 5)", ["POINT(55 55)", "POINT(65 65)"]
7+
5, true, false, "POINT(5.5 5.5)", ["POINT(0 0)","POINT(11 11)"], ["POINT(0 0)","POINT(11 11)"], "POINT(0 0)", ["POINT(55 55)", "POINT(65 65)"]
8+
6, true, false, "POINT(0.0 -5.0)", ["POINT(-9 -19)","POINT(9 9)"], ["POINT(-9 -19)","POINT(9 9)"], "POINT(-9 -19)", ["POINT(55 55)", "POINT(65 65)"]
9+
7, false, false, "POINT(10.0 10.0)", ["POINT(5 15)", "POINT(15 5)"], ["POINT(5 15)", "POINT(15 5)"], "POINT(5 15)", ["POINT(55 55)", "POINT(65 65)"]
10+
8, false, false, "POINT(5.5 5.5)", ["POINT(0 11)","POINT(11 0)"], ["POINT(0 11)","POINT(11 0)"], "POINT(0 11)", ["POINT(55 55)", "POINT(65 65)"]
11+
9, false, false, "POINT(19.0 9.0)", "POINT(19 9)", "POINT(19 9)", "POINT(19 9)", ["POINT(55 55)", "POINT(65 65)"]
12+
10, false, false, "POINT(5.0 -5.0)", ["POINT(-9 -19)","POINT(19 9)"], ["POINT(-9 -19)","POINT(19 9)"], "POINT(-9 -19)", ["POINT(55 55)", "POINT(65 65)"]
13+
11, true, false, "POINT(0.0 0.0)", ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 55)"], ["POINT(55 55)", "POINT(65 65)"]
14+
12, true, false, "POINT(0.0 0.0)", ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"], ["POINT(0 0)", "POINT(55 54)"], ["POINT(55 55)", "POINT(65 65)"]

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,92 @@ id:l | intersects:boolean | within:boolean | st_intersects:boolean | st_within:b
6060
12 | true | false | true | false | false | "POINT(0.0 0.0)" | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"]
6161
;
6262

63+
spatialDistance
64+
required_capability: st_distance
65+
required_capability: spatial_distance_supports_multivalues
66+
67+
FROM multivalue_points
68+
| EVAL distance_origin=ST_DISTANCE(location, TO_GEOPOINT("POINT(0 0)"))
69+
| EVAL distance_subset=ST_DISTANCE(location, subset)
70+
| EVAL distance_disjoint=ST_DISTANCE(location, disjoint)
71+
| EVAL distance_far=ST_DISTANCE(location, TO_GEOPOINT("POINT(55 55)"))
72+
| KEEP id, distance_origin, distance_subset, distance_disjoint, distance_far, location, subset, disjoint
73+
| SORT id
74+
;
75+
76+
id:l | distance_origin:d | distance_subset:d | distance_disjoint:d | distance_far:d | location:geo_point | subset:geo_point | disjoint:geo_point
77+
0 | 785768.2986429982 | 0.0 | 7114305.127148048 | 7114305.127148048 | ["POINT(5 5)", "POINT(-5 5)"] | "POINT(5 5)" | ["POINT(55 55)", "POINT(65 65)"]
78+
1 | 111195.07310665186 | 0.0 | 7775410.295475619 | 7775410.295475619 | ["POINT(0 1)","POINT(1 0)"] | "POINT(0 1)" | ["POINT(55 55)", "POINT(65 65)"]
79+
2 | 1412359.654429245 | 0.0 | 6511042.96320646 | 6511042.96320646 | "POINT(9 9)" | "POINT(9 9)" | ["POINT(55 55)", "POINT(65 65)"]
80+
3 | 1412359.654429245 | 0.0 | 6511042.96320646 | 6511042.96320646 | ["POINT(-9 -9)","POINT(9 9)"] | "POINT(-9 -9)" | ["POINT(55 55)", "POINT(65 65)"]
81+
4 | 785768.2986429982 | 0.0 | 5612483.563947934 | 5612483.563947934 | ["POINT(5 5)", "POINT(15 15)"] | "POINT(5 5)" | ["POINT(55 55)", "POINT(65 65)"]
82+
5 | 0.0 | 0.0 | 6210584.082742179 | 6210584.082742179 | ["POINT(0 0)","POINT(11 11)"] | "POINT(0 0)" | ["POINT(55 55)", "POINT(65 65)"]
83+
6 | 1412359.654429245 | 0.0 | 6511042.96320646 | 6511042.96320646 | ["POINT(-9 -19)","POINT(9 9)"] | "POINT(-9 -19)" | ["POINT(55 55)", "POINT(65 65)"]
84+
7 | 1756128.8127267 | 0.0 | 6157935.487780502 | 6157935.487780502 | ["POINT(5 15)", "POINT(15 5)"] | "POINT(5 15)" | ["POINT(55 55)", "POINT(65 65)"]
85+
8 | 1223145.8694147274 | 0.0 | 6823348.604540896 | 6823348.604540896 | ["POINT(0 11)","POINT(11 0)"] | "POINT(0 11)" | ["POINT(55 55)", "POINT(65 65)"]
86+
9 | 2329806.5462053656 | 0.0 | 6014935.534393433 | 6014935.534393433 | "POINT(19 9)" | "POINT(19 9)" | ["POINT(55 55)", "POINT(65 65)"]
87+
10 | 2329806.5462053656 | 0.0 | 6014935.534393433 | 6014935.534393433 | ["POINT(-9 -19)","POINT(19 9)"] | "POINT(-9 -19)" | ["POINT(55 55)", "POINT(65 65)"]
88+
11 | 0.0 | 0.0 | 0.0 | 0.0 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"] | ["POINT(0 0)", "POINT(55 55)"] | ["POINT(55 55)", "POINT(65 65)"]
89+
12 | 0.0 | 0.0 | 0.0 | 0.0 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"] | ["POINT(0 0)", "POINT(55 54)"] | ["POINT(55 55)", "POINT(65 65)"]
90+
;
91+
92+
whereSpatialDistanceTwoFields
93+
required_capability: st_distance
94+
required_capability: spatial_distance_supports_multivalues
95+
96+
FROM multivalue_points
97+
| WHERE ST_DISTANCE(location, disjoint) < 6200000
98+
| KEEP id, location
99+
| SORT id
100+
;
101+
102+
id:l | location:geo_point
103+
4 | ["POINT(5 5)", "POINT(15 15)"]
104+
7 | ["POINT(5 15)", "POINT(15 5)"]
105+
9 | "POINT(19 9)"
106+
10 | ["POINT(-9 -19)","POINT(19 9)"]
107+
11 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"]
108+
12 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"]
109+
;
110+
111+
whereSpatialDistanceKeyword
112+
required_capability: st_distance
113+
required_capability: spatial_distance_supports_multivalues
114+
115+
FROM multivalue_points
116+
| EVAL lk=lk::geo_point
117+
| WHERE ST_DISTANCE(lk, disjoint) < 6200000
118+
| KEEP id, location
119+
| SORT id
120+
;
121+
122+
id:l | location:geo_point
123+
4 | ["POINT(5 5)", "POINT(15 15)"]
124+
7 | ["POINT(5 15)", "POINT(15 5)"]
125+
9 | "POINT(19 9)"
126+
10 | ["POINT(-9 -19)","POINT(19 9)"]
127+
11 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"]
128+
12 | ["POINT(0 0)", "POINT(55 55)", "POINT(-55 -55)"]
129+
;
130+
131+
spatialDistanceFilterTwoFieldStats
132+
required_capability: st_distance
133+
required_capability: spatial_distance_supports_multivalues
134+
135+
FROM multivalue_points
136+
| EVAL distance_disjoint=ST_DISTANCE(location, disjoint)
137+
| WHERE distance_disjoint > 0
138+
| EVAL kkm = TO_INTEGER(distance_disjoint / 1000000)
139+
| STATS c=COUNT(*) BY kkm
140+
| SORT kkm ASC
141+
;
142+
143+
c:long | kkm:integer
144+
5 | 6
145+
5 | 7
146+
1 | 8
147+
;
148+
63149
whereIntersectsPolygon
64150
required_capability: st_intersects
65151

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,30 +2222,33 @@ wkt:keyword | pt:cartesian_point | distance:double
22222222

22232223
twoCitiesPointDistanceCartesian
22242224
required_capability: st_distance
2225+
required_capability: spatial_distance_supports_multivalues
22252226

22262227
ROW p1 = TO_CARTESIANPOINT("POINT(-90.82814 29.79511)"), p2 = TO_CARTESIANPOINT("POINT(-90.79731509999999 29.8835389)")
22272228
| EVAL d = ST_DISTANCE(p1, p2)
22282229
;
22292230

22302231
p1:cartesian_point | p2:cartesian_point | d:double
2231-
POINT (-90.82814 29.79511) | POINT (-90.79731509999999 29.8835389) | 0.09364744959271905
2232+
POINT (-90.82814 29.79511) | POINT (-90.79731509999999 29.8835389) | 0.09364636296011444
22322233
;
22332234

22342235
airportCartesianCityLocationPointDistance
22352236
required_capability: st_distance
2237+
required_capability: spatial_distance_supports_multivalues
22362238

22372239
FROM airports_web
22382240
| EVAL distance = ST_DISTANCE(location, TO_CARTESIANPOINT("POINT(1402900 7490000)"))
22392241
| WHERE distance < 1000000
22402242
| STATS distance=AVG(distance), min=min(distance), max=max(distance), count=COUNT()
22412243
;
22422244

2243-
distance:double | min:double | max:double | count:long
2244-
676858.3463435044 | 7358.02077507206 | 971112.9731194031 | 12
2245+
distance:double | min:double | max:double | count:long
2246+
676858.3629952326 | 7358.012830411482 | 971113.1663946278 | 12
22452247
;
22462248

22472249
airportCartesianDistanceToCityCopenhagen
22482250
required_capability: st_distance
2251+
required_capability: spatial_distance_supports_multivalues
22492252

22502253
// tag::st_distance-airports_web[]
22512254
FROM airports_web
@@ -2257,7 +2260,7 @@ FROM airports_web
22572260

22582261
// tag::st_distance-airports_web-result[]
22592262
abbrev:k | name:text | location:cartesian_point | distance:d
2260-
CPH | Copenhagen | POINT(1408119.2975413958 7484813.53657096) | 7358.02077507206
2263+
CPH | Copenhagen | POINT(1408119.2975413958 7484813.53657096) | 7358.012830411482
22612264
// end::st_distance-airports_web-result[]
22622265
;
22632266

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

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

0 commit comments

Comments
 (0)