Skip to content

Commit e44c824

Browse files
committed
Support MV_CONTAINS
1 parent 385fcce commit e44c824

File tree

5 files changed

+85
-50
lines changed

5 files changed

+85
-50
lines changed

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

Lines changed: 3 additions & 0 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/mv_contains.json

Lines changed: 54 additions & 0 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ POINT (12.6493508684508 55.6285017221528) | 13686180 | 427683 | 1336
123123

124124
geohashLiteralMv
125125
required_capability: spatial_grid_types
126+
required_capability: fn_mv_contains
126127

127128
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
128129
| EVAL geohash4 = ST_GEOHASH(location, 4),
@@ -133,7 +134,7 @@ ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
133134
| EVAL description = MV_CONCAT(chain::keyword, " --> ")
134135
| EVAL top = MV_LAST(chain)
135136
| EVAL bottom = MV_FIRST(chain)
136-
//| WHERE MV_CONTAINS(chain, first) AND MV_CONTAINS(chain, last)
137+
| WHERE MV_CONTAINS(chain, top) AND MV_CONTAINS(chain, bottom)
137138
| KEEP location, top, bottom, chain, description
138139
;
139140

@@ -521,6 +522,7 @@ POINT (12.6493508684508 55.6285017221528) | 1152921508901814277 | 86469113060261
521522

522523
geotileLiteralMv
523524
required_capability: spatial_grid_types
525+
required_capability: fn_mv_contains
524526

525527
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
526528
| EVAL geotile4 = ST_GEOTILE(location, 4),
@@ -531,7 +533,7 @@ ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
531533
| EVAL description = MV_CONCAT(chain::keyword, " --> ")
532534
| EVAL top = MV_LAST(chain)
533535
| EVAL bottom = MV_FIRST(chain)
534-
//| WHERE MV_CONTAINS(chain, first) AND MV_CONTAINS(chain, last)
536+
| WHERE MV_CONTAINS(chain, top) AND MV_CONTAINS(chain, bottom)
535537
| KEEP location, top, bottom, chain, description
536538
;
537539

@@ -878,6 +880,7 @@ POINT (12.6493508684508 55.6285017221528) | 595020895127339007 | 590517321269772
878880

879881
geohexLiteralMv
880882
required_capability: spatial_grid_types
883+
required_capability: fn_mv_contains
881884

882885
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
883886
| EVAL geohex4 = ST_GEOHEX(location, 4),
@@ -888,7 +891,7 @@ ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
888891
| EVAL description = MV_CONCAT(chain::keyword, " --> ")
889892
| EVAL top = MV_LAST(chain)
890893
| EVAL bottom = MV_FIRST(chain)
891-
//| WHERE MV_CONTAINS(chain, first) AND MV_CONTAINS(chain, last)
894+
| WHERE MV_CONTAINS(chain, top) AND MV_CONTAINS(chain, bottom)
892895
| KEEP location, top, bottom, chain, description
893896
;
894897

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public MvContains(
9393
"double",
9494
"geo_point",
9595
"geo_shape",
96+
"geohash",
97+
"geotile",
98+
"geohex",
9699
"integer",
97100
"ip",
98101
"keyword",
@@ -113,6 +116,9 @@ public MvContains(
113116
"double",
114117
"geo_point",
115118
"geo_shape",
119+
"geohash",
120+
"geotile",
121+
"geohex",
116122
"integer",
117123
"ip",
118124
"keyword",

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvContainsTests.java

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.GEO;
3636
import static org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier.TypedData.MULTI_ROW_NULL;
3737
import static org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier.TypedData.NULL;
38+
import static org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSliceTests.randomGrid;
3839
import static org.hamcrest.Matchers.equalTo;
3940

4041
public class MvContainsTests extends AbstractScalarFunctionTestCase {
@@ -100,56 +101,24 @@ private static void ints(List<TestCaseSupplier> suppliers) {
100101
}
101102

102103
private static void longs(List<TestCaseSupplier> suppliers) {
103-
suppliers.add(new TestCaseSupplier(List.of(DataType.LONG, DataType.LONG), () -> {
104-
List<Long> field1 = randomList(1, 10, ESTestCase::randomLong);
105-
List<Long> field2 = randomList(1, 10, ESTestCase::randomLong);
106-
var result = field1.containsAll(field2);
107-
return new TestCaseSupplier.TestCase(
108-
List.of(
109-
new TestCaseSupplier.TypedData(field1, DataType.LONG, "field1"),
110-
new TestCaseSupplier.TypedData(field2, DataType.LONG, "field2")
111-
),
112-
"MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]",
113-
DataType.BOOLEAN,
114-
equalTo(result)
115-
);
116-
}));
117-
suppliers.add(new TestCaseSupplier(List.of(DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG), () -> {
118-
List<Long> field1 = randomList(1, 10, ESTestCase::randomLong);
119-
List<Long> field2 = randomList(1, 10, ESTestCase::randomLong);
120-
var result = field1.containsAll(field2);
121-
return new TestCaseSupplier.TestCase(
122-
List.of(
123-
new TestCaseSupplier.TypedData(field1, DataType.UNSIGNED_LONG, "field1"),
124-
new TestCaseSupplier.TypedData(field2, DataType.UNSIGNED_LONG, "field2")
125-
),
126-
"MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]",
127-
DataType.BOOLEAN,
128-
equalTo(result)
129-
);
130-
}));
131-
suppliers.add(new TestCaseSupplier(List.of(DataType.DATETIME, DataType.DATETIME), () -> {
132-
List<Long> field1 = randomList(1, 10, ESTestCase::randomLong);
133-
List<Long> field2 = randomList(1, 10, ESTestCase::randomLong);
134-
var result = field1.containsAll(field2);
135-
return new TestCaseSupplier.TestCase(
136-
List.of(
137-
new TestCaseSupplier.TypedData(field1, DataType.DATETIME, "field1"),
138-
new TestCaseSupplier.TypedData(field2, DataType.DATETIME, "field2")
139-
),
140-
"MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]",
141-
DataType.BOOLEAN,
142-
equalTo(result)
143-
);
144-
}));
145-
suppliers.add(new TestCaseSupplier(List.of(DataType.DATE_NANOS, DataType.DATE_NANOS), () -> {
146-
List<Long> field1 = randomList(1, 10, ESTestCase::randomNonNegativeLong);
147-
List<Long> field2 = randomList(1, 10, ESTestCase::randomNonNegativeLong);
104+
addLongTestCase(suppliers, DataType.LONG, ESTestCase::randomLong);
105+
addLongTestCase(suppliers, DataType.UNSIGNED_LONG, ESTestCase::randomLong);
106+
addLongTestCase(suppliers, DataType.DATETIME, ESTestCase::randomLong);
107+
addLongTestCase(suppliers, DataType.DATE_NANOS, ESTestCase::randomNonNegativeLong);
108+
for (DataType gridType : new DataType[] { DataType.GEOHASH, DataType.GEOTILE, DataType.GEOHEX }) {
109+
addLongTestCase(suppliers, gridType, () -> randomGrid(gridType));
110+
}
111+
}
112+
113+
private static void addLongTestCase(List<TestCaseSupplier> suppliers, DataType dataType, Supplier<Long> longSupplier) {
114+
suppliers.add(new TestCaseSupplier(List.of(dataType, dataType), () -> {
115+
List<Long> field1 = randomList(1, 10, longSupplier);
116+
List<Long> field2 = randomList(1, 10, longSupplier);
148117
var result = field1.containsAll(field2);
149118
return new TestCaseSupplier.TestCase(
150119
List.of(
151-
new TestCaseSupplier.TypedData(field1, DataType.DATE_NANOS, "field1"),
152-
new TestCaseSupplier.TypedData(field2, DataType.DATE_NANOS, "field2")
120+
new TestCaseSupplier.TypedData(field1, dataType, "field1"),
121+
new TestCaseSupplier.TypedData(field2, dataType, "field2")
153122
),
154123
"MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]",
155124
DataType.BOOLEAN,

0 commit comments

Comments
 (0)