Skip to content

Commit ff40585

Browse files
authored
MV_CONTAINS avoid autoboxing (#135991)
Changed logic to avoid autoboxing in MvContains by adding `hasValue` methods for type-specific blocks. Renamed process method and evaluator parameters Removed continue on empty, addressing bug. Updated test cases to include empty string scenarios and added the v1 of shame to fn_mv_contains capability.
1 parent 2b91dd5 commit ff40585

File tree

17 files changed

+358
-224
lines changed

17 files changed

+358
-224
lines changed

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/BooleanBlock.java

Lines changed: 18 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/compute/src/main/generated-src/org/elasticsearch/compute/data/BytesRefBlock.java

Lines changed: 20 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/compute/src/main/generated-src/org/elasticsearch/compute/data/DoubleBlock.java

Lines changed: 18 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/compute/src/main/generated-src/org/elasticsearch/compute/data/FloatBlock.java

Lines changed: 18 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/compute/src/main/generated-src/org/elasticsearch/compute/data/IntBlock.java

Lines changed: 18 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/compute/src/main/generated-src/org/elasticsearch/compute/data/LongBlock.java

Lines changed: 18 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/compute/src/main/java/org/elasticsearch/compute/data/X-Block.java.st

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ $else$
5454
$type$ get$Type$(int valueIndex);
5555
$endif$
5656

57+
/**
58+
* Checks if this block has the given value at position. If at this index we have a
59+
* multivalue, then it returns true if any values match.
60+
*
61+
* @param position the index at which we should check the value(s)
62+
* @param value the value to check against
63+
$if(BytesRef)$
64+
* @param scratch the scratch BytesRef to use for this operation
65+
$endif$
66+
*/
67+
default boolean hasValue(int position, $type$ value$if(BytesRef)$, BytesRef scratch$endif$) {
68+
final var count = getValueCount(position);
69+
final var startIndex = getFirstValueIndex(position);
70+
for (int index = startIndex; index < startIndex + count; index++) {
71+
$if(BytesRef)$
72+
var ref = getBytesRef(index, scratch);
73+
if (value.equals(ref)) {
74+
return true;
75+
}
76+
$else$
77+
if (value == get$Type$(index)) {
78+
return true;
79+
}
80+
$endif$
81+
}
82+
return false;
83+
}
84+
5785
@Override
5886
$Type$Vector asVector();
5987

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +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
126+
required_capability: fn_mv_contains_v1
127127

128128
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
129129
| EVAL geohash4 = ST_GEOHASH(location, 4),
@@ -580,7 +580,7 @@ POINT (12.6493508684508 55.6285017221528) | 1152921508901814277 | 86469113060261
580580

581581
geotileLiteralMv
582582
required_capability: spatial_grid_types
583-
required_capability: fn_mv_contains
583+
required_capability: fn_mv_contains_v1
584584

585585
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
586586
| EVAL geotile4 = ST_GEOTILE(location, 4),
@@ -996,7 +996,7 @@ POINT (12.6493508684508 55.6285017221528) | 595020895127339007 | 590517321269772
996996

997997
geohexLiteralMv
998998
required_capability: spatial_grid_types
999-
required_capability: fn_mv_contains
999+
required_capability: fn_mv_contains_v1
10001000

10011001
ROW location = TO_GEOPOINT("POINT(12.6493508684508 55.6285017221528)")
10021002
| EVAL geohex4 = ST_GEOHEX(location, 4),

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ null | 0
20542054
;
20552055

20562056
mvContains
2057-
required_capability: fn_mv_contains
2057+
required_capability: fn_mv_contains_v1
20582058
// tag::mv_contains[]
20592059
ROW set = ["a", "b", "c"], element = "a"
20602060
| EVAL set_contains_element = mv_contains(set, element)
@@ -2068,7 +2068,7 @@ set:keyword | element:keyword | set_contains_element:boolean
20682068
;
20692069

20702070
mvContains_bothsides
2071-
required_capability: fn_mv_contains
2071+
required_capability: fn_mv_contains_v1
20722072
// tag::mv_contains_bothsides[]
20732073
ROW setA = ["a","c"], setB = ["a", "b", "c"]
20742074
| EVAL a_subset_of_b = mv_contains(setB, setA)
@@ -2083,7 +2083,7 @@ setA:keyword | setB:keyword | a_subset_of_b:boolean | b_subset_of_a:boolean
20832083
;
20842084

20852085
mvContainsCombinations
2086-
required_capability: fn_mv_contains
2086+
required_capability: fn_mv_contains_v1
20872087

20882088
ROW a = "a", b = ["a", "b", "c"], n = null
20892089
| EVAL aa = mv_contains(a, a),
@@ -2100,33 +2100,36 @@ a | [a, b, c] | null | true | true | false | true
21002100
;
21012101

21022102
mvContainsCombinations_multirow
2103-
required_capability: fn_mv_contains
2103+
required_capability: fn_mv_contains_v1
21042104

2105-
ROW row_number = [1,2,3,4,5], element = "e", n = null, setA = ["b","d"], setB = ["a", "c", "e"]
2105+
ROW row_number = [0,1,2,3,4,5], element = "e", n = null, emptyStringSet = [""], setA = ["b","d"], setB = ["a", "c", "e"]
21062106
| MV_EXPAND row_number
21072107
| EVAL superset = CASE(
2108-
row_number == 1, ["a","e"],
2109-
row_number == 2, ["b","d"],
2110-
row_number == 3, null,
2111-
row_number == 4, ["a","e","c","b","d"],
2112-
row_number == 5, ["a","d","c","b","e"],
2108+
row_number == 0, ["a","e"],
2109+
row_number == 1, ["b","d"],
2110+
row_number == 2, null,
2111+
row_number == 3, ["a","e","c","b","d"],
2112+
row_number == 4, ["a","d","c","b","e"],
2113+
row_number == 5, ["a","d","c","b","","e"],
21132114
null)
2114-
| EVAL contains_element = mv_contains(superset, element),
2115-
contains_null = mv_contains(superset, n),
2116-
contains_setA = mv_contains(superset, setA),
2117-
contains_setB = mv_contains(superset, setB)
2115+
| EVAL contains_element = mv_contains(superset, element),
2116+
contains_null = mv_contains(superset, n),
2117+
contains_emptyStringSet = mv_contains(superset, emptyStringSet),
2118+
contains_setA = mv_contains(superset, setA),
2119+
contains_setB = mv_contains(superset, setB)
21182120
;
21192121

2120-
row_number:INTEGER | element:keyword | n:null | setA:keyword | setB:keyword | superset:keyword |contains_element:boolean | contains_null:boolean | contains_setA:boolean | contains_setB:boolean
2121-
1 | "e" | null | ["b","d"] | ["a", "c", "e"] | ["a","e"] | true | true | false | false
2122-
2 | "e" | null | ["b","d"] | ["a", "c", "e"] | ["b","d"] | false | true | true | false
2123-
3 | "e" | null | ["b","d"] | ["a", "c", "e"] | null | false | true | false | false
2124-
4 | "e" | null | ["b","d"] | ["a", "c", "e"] | ["a","e","c","b","d"] | true | true | true | true
2125-
5 | "e" | null | ["b","d"] | ["a", "c", "e"] | ["a","d","c","b","e"] | true | true | true | true
2122+
row_number:INTEGER | element:keyword | n:null | emptyStringSet:keyword | setA:keyword | setB:keyword | superset:keyword |contains_element:boolean | contains_null:boolean | contains_emptyStringSet:boolean | contains_setA:boolean | contains_setB:boolean
2123+
0 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | ["a","e"] | true | true | false | false | false
2124+
1 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | ["b","d"] | false | true | false | true | false
2125+
2 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | null | false | true | false | false | false
2126+
3 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | ["a","e","c","b","d"] | true | true | false | true | true
2127+
4 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | ["a","d","c","b","e"] | true | true | false | true | true
2128+
5 | "e" | null | [""] | ["b","d"] | ["a", "c", "e"] | ["a","d","c","b","","e"] | true | true | true | true | true
21262129
;
21272130

21282131
mvContains_where
2129-
required_capability: fn_mv_contains
2132+
required_capability: fn_mv_contains_v1
21302133
// tag::mv_contains_where[]
21312134
FROM airports
21322135
| WHERE mv_contains(type, ["major","military"]) AND scalerank == 9

0 commit comments

Comments
 (0)