Skip to content

Commit 0af600e

Browse files
authored
ESQL: Extends constant MVs handling with warnings to general binary comparisons (elastic#137387) (elastic#137490)
(cherry picked from commit 5e35a4e)
1 parent ae81623 commit 0af600e

File tree

5 files changed

+183
-1
lines changed

5 files changed

+183
-1
lines changed

docs/changelog/137387.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137387
2+
summary: Extends constant MVs handling with warnings to general binary comparisons
3+
area: ES|QL
4+
type: bug
5+
issues: []

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

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
116116
is_rehired:boolean
117117
;
118118

119+
mvBoolean_NotEquals_MultiValueConstant
120+
required_capability: fix_mv_constant_equals_field
121+
122+
FROM employees
123+
| WHERE is_rehired != ([true, false])
124+
| KEEP is_rehired
125+
;
126+
warning:Line 2:9: evaluation of [is_rehired != ([true, false])] failed, treating result as null. Only first 20 failures recorded.
127+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
128+
129+
is_rehired:boolean
130+
;
131+
119132
computedBoolean_Equals_MultiValueConstant
120133
required_capability: fix_mv_constant_equals_field
121134

@@ -130,6 +143,20 @@ warning:Line 3:9: java.lang.IllegalArgumentException: single-value function enco
130143
x:boolean
131144
;
132145

146+
computedBoolean_NotEquals_MultiValueConstant
147+
required_capability: fix_mv_constant_comparison_field
148+
149+
FROM employees
150+
| EVAL x = gender IS NULL
151+
| WHERE x != [true, false]
152+
| KEEP x
153+
;
154+
warning:Line 3:9: evaluation of [x != [true, false]] failed, treating result as null. Only first 20 failures recorded.
155+
warning:Line 3:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
156+
157+
x:boolean
158+
;
159+
133160
computedBoolean_Equals_SingleMultiValueConstant
134161
required_capability: fix_mv_constant_equals_field
135162

@@ -169,3 +196,120 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
169196

170197
salary_change:double
171198
;
199+
200+
svDouble_NotEquals_MultiValueConstant
201+
required_capability: fix_mv_constant_comparison_field
202+
203+
FROM employees
204+
| WHERE salary::double != [1,2,3]
205+
| KEEP salary
206+
;
207+
warning:Line 2:9: evaluation of [salary::double != [1,2,3]] failed, treating result as null. Only first 20 failures recorded.
208+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
209+
210+
salary:integer
211+
;
212+
213+
integer_GreaterThan_MultiValueConstant
214+
required_capability: fix_mv_constant_comparison_field
215+
216+
FROM employees
217+
| WHERE salary > [1,2,3]
218+
| KEEP salary
219+
;
220+
warning:Line 2:9: evaluation of [salary > [1,2,3]] failed, treating result as null. Only first 20 failures recorded.
221+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
222+
223+
salary:integer
224+
;
225+
226+
keyword_GreaterThan_MultiValueConstant
227+
required_capability: fix_mv_constant_comparison_field
228+
229+
FROM employees
230+
| WHERE first_name > ["A","B"]
231+
| KEEP first_name
232+
;
233+
warning:Line 2:9: evaluation of [first_name > [\"A\",\"B\"]] failed, treating result as null. Only first 20 failures recorded.
234+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
235+
236+
first_name:keyword
237+
;
238+
239+
dateNanos_GreaterThan_MultiValueConstant
240+
required_capability: fix_mv_constant_comparison_field
241+
242+
FROM date_nanos
243+
| WHERE nanos > [1.0,2.0]::date_nanos
244+
;
245+
warning:Line 2:9: evaluation of [nanos > [1.0,2.0]::date_nanos] failed, treating result as null. Only first 20 failures recorded.
246+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
247+
248+
millis:date | nanos:date_nanos | num:long
249+
;
250+
251+
long_GreaterThan_MultiValueConstant
252+
required_capability: fix_mv_constant_comparison_field
253+
254+
FROM date_nanos
255+
| WHERE num > [1,2]
256+
;
257+
warning:Line 2:9: evaluation of [num > [1,2]] failed, treating result as null. Only first 20 failures recorded.
258+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
259+
260+
millis:date | nanos:date_nanos | num:long
261+
;
262+
263+
version_GreaterThan_MultiValueConstant
264+
required_capability: fix_mv_constant_comparison_field
265+
266+
FROM apps
267+
| WHERE version > to_ver(["1.2.3.4","127.0.0.1"])
268+
;
269+
warning:Line 2:9: evaluation of [version > to_ver([\"1.2.3.4\",\"127.0.0.1\"])] failed, treating result as null. Only first 20 failures recorded.
270+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
271+
272+
id:i | name:s | version:v
273+
;
274+
275+
ip_GreaterThanOrLessThan_MultiValueConstant
276+
required_capability: fix_mv_constant_comparison_field
277+
278+
from hosts
279+
| where ip1 > ["1.2.3.4","127.0.0.1"]::ip OR ip0 < to_ip(["1.2.3.4","127.0.0.1"])
280+
| keep ip1, ip0
281+
;
282+
warning:Line 2:9: evaluation of [ip1 > [\"1.2.3.4\",\"127.0.0.1\"]::ip] failed, treating result as null. Only first 20 failures recorded.
283+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
284+
warning:Line 2:46: evaluation of [ip0 < to_ip([\"1.2.3.4\",\"127.0.0.1\"])] failed, treating result as null. Only first 20 failures recorded.
285+
warning:Line 2:46: java.lang.IllegalArgumentException: single-value function encountered multi-value
286+
287+
ip1:ip | ip0:ip
288+
;
289+
290+
ul_GreaterThan_MultiValueConstant
291+
required_capability: fix_mv_constant_comparison_field
292+
293+
from ul_logs
294+
| where bytes_in > [16002960716282089759, 17281501450843634251]
295+
| keep bytes_in
296+
;
297+
warning:Line 2:9: evaluation of [bytes_in > [16002960716282089759, 17281501450843634251]] failed, treating result as null. Only first 20 failures recorded.
298+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
299+
300+
bytes_in:ul
301+
;
302+
303+
ul_NotEquals_MultiValueConstant
304+
required_capability: fix_mv_constant_comparison_field
305+
306+
from ul_logs
307+
| where bytes_in != [16002960716282089759, 17281501450843634251]
308+
| keep bytes_in
309+
;
310+
warning:Line 2:9: evaluation of [bytes_in != [16002960716282089759, 17281501450843634251]] failed, treating result as null. Only first 20 failures recorded.
311+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
312+
313+
bytes_in:ul
314+
;
315+

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,18 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
25912591
@timestamp:date | message:text
25922592
;
25932593

2594+
mvStringNotEqualsMultiValueConstant
2595+
required_capability: fix_mv_constant_comparison_field
2596+
FROM mv_text
2597+
| WHERE message != ["Connected to 10.1.0.1", "Banana"]
2598+
| KEEP @timestamp, message
2599+
;
2600+
warning:Line 2:9: evaluation of [message != [\"Connected to 10.1.0.1\", \"Banana\"]] failed, treating result as null. Only first 20 failures recorded.
2601+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
2602+
2603+
@timestamp:date | message:text
2604+
;
2605+
25942606
mvString_IN_MultiValueConstant
25952607
required_capability: fix_mv_constant_equals_field
25962608
FROM mv_text
@@ -2627,6 +2639,18 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
26272639
emp_no:integer | job_positions:keyword
26282640
;
26292641

2642+
mvKeywordNotEqualsMultiValueConstant
2643+
required_capability: fix_mv_constant_comparison_field
2644+
FROM employees
2645+
| WHERE job_positions != ["Tech Lead" , "Data Scientist", "Senior Team Lead"]
2646+
| KEEP emp_no, job_positions
2647+
;
2648+
warning:Line 2:9: evaluation of [job_positions != [\"Tech Lead\" , \"Data Scientist\", \"Senior Team Lead\"]] failed, treating result as null. Only first 20 failures recorded.
2649+
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
2650+
2651+
emp_no:integer | job_positions:keyword
2652+
;
2653+
26302654
url_encode sample for docs
26312655
required_capability: url_encode
26322656

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@ public enum Cap {
16511651
*/
16521652
FIX_REPLACE_ALIASING_EVAL_WITH_PROJECT_SHADOWING,
16531653

1654+
FIX_MV_CONSTANT_COMPARISON_FIELD,
16541655
// Last capability should still have a comma for fewer merge conflicts when adding new ones :)
16551656
// This comment prevents the semicolon from being on the previous capability when Spotless formats the file.
16561657
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/EsqlBinaryComparison.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.xpack.esql.core.expression.Expressions;
2323
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
2424
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
25+
import org.elasticsearch.xpack.esql.core.expression.Literal;
2526
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
2627
import org.elasticsearch.xpack.esql.core.expression.TypedAttribute;
2728
import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison;
@@ -47,6 +48,7 @@
4748
import java.time.OffsetTime;
4849
import java.time.ZoneId;
4950
import java.time.ZonedDateTime;
51+
import java.util.Collection;
5052
import java.util.List;
5153
import java.util.Map;
5254

@@ -329,7 +331,13 @@ public static String formatIncompatibleTypesMessage(DataType leftType, DataType
329331

330332
@Override
331333
public Translatable translatable(LucenePushdownPredicates pushdownPredicates) {
332-
if (right().foldable()) {
334+
if (right() instanceof Literal lit) {
335+
// Multi-valued literals are not supported going further. This also makes sure that we are handling multi-valued literals with
336+
// a "warning" header, as well (see EqualsKeywordsEvaluator, for example, where lhs and rhs are both dealt with equally when
337+
// it comes to multi-value handling).
338+
if (lit.value() instanceof Collection<?>) {
339+
return Translatable.NO;
340+
}
333341
if (pushdownPredicates.isPushableFieldAttribute(left())) {
334342
return Translatable.YES;
335343
}

0 commit comments

Comments
 (0)