Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/137387.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137387
summary: Extends constant MVs handling with warnings to general binary comparisons
area: ES|QL
type: bug
issues: []
144 changes: 144 additions & 0 deletions x-pack/plugin/esql/qa/testFixtures/src/main/resources/folding.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
is_rehired:boolean
;

mvBoolean_NotEquals_MultiValueConstant
required_capability: fix_mv_constant_equals_field

FROM employees
| WHERE is_rehired != ([true, false])
| KEEP is_rehired
;
warning:Line 2:9: evaluation of [is_rehired != ([true, false])] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

is_rehired:boolean
;

computedBoolean_Equals_MultiValueConstant
required_capability: fix_mv_constant_equals_field

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

computedBoolean_NotEquals_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM employees
| EVAL x = gender IS NULL
| WHERE x != [true, false]
| KEEP x
;
warning:Line 3:9: evaluation of [x != [true, false]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 3:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

x:boolean
;

computedBoolean_Equals_SingleMultiValueConstant
required_capability: fix_mv_constant_equals_field

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

salary_change:double
;

svDouble_NotEquals_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM employees
| WHERE salary::double != [1,2,3]
| KEEP salary
;
warning:Line 2:9: evaluation of [salary::double != [1,2,3]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

salary:integer
;

integer_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM employees
| WHERE salary > [1,2,3]
| KEEP salary
;
warning:Line 2:9: evaluation of [salary > [1,2,3]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

salary:integer
;

keyword_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM employees
| WHERE first_name > ["A","B"]
| KEEP first_name
;
warning:Line 2:9: evaluation of [first_name > [\"A\",\"B\"]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

first_name:keyword
;

dateNanos_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM date_nanos
| WHERE nanos > [1.0,2.0]::date_nanos
;
warning:Line 2:9: evaluation of [nanos > [1.0,2.0]::date_nanos] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

millis:date | nanos:date_nanos | num:long
;

long_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM date_nanos
| WHERE num > [1,2]
;
warning:Line 2:9: evaluation of [num > [1,2]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

millis:date | nanos:date_nanos | num:long
;

version_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

FROM apps
| WHERE version > to_ver(["1.2.3.4","127.0.0.1"])
;
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.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

id:i | name:s | version:v
;

ip_GreaterThanOrLessThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

from hosts
| where ip1 > ["1.2.3.4","127.0.0.1"]::ip OR ip0 < to_ip(["1.2.3.4","127.0.0.1"])
| keep ip1, ip0
;
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.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value
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.
warning:Line 2:46: java.lang.IllegalArgumentException: single-value function encountered multi-value

ip1:ip | ip0:ip
;

ul_GreaterThan_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

from ul_logs
| where bytes_in > [16002960716282089759, 17281501450843634251]
| keep bytes_in
;
warning:Line 2:9: evaluation of [bytes_in > [16002960716282089759, 17281501450843634251]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

bytes_in:ul
;

ul_NotEquals_MultiValueConstant
required_capability: fix_mv_constant_comparison_field

from ul_logs
| where bytes_in != [16002960716282089759, 17281501450843634251]
| keep bytes_in
;
warning:Line 2:9: evaluation of [bytes_in != [16002960716282089759, 17281501450843634251]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

bytes_in:ul
;

Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,18 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
@timestamp:date | message:text
;

mvStringNotEqualsMultiValueConstant
required_capability: fix_mv_constant_comparison_field
FROM mv_text
| WHERE message != ["Connected to 10.1.0.1", "Banana"]
| KEEP @timestamp, message
;
warning:Line 2:9: evaluation of [message != [\"Connected to 10.1.0.1\", \"Banana\"]] failed, treating result as null. Only first 20 failures recorded.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

@timestamp:date | message:text
;

mvString_IN_MultiValueConstant
required_capability: fix_mv_constant_equals_field
FROM mv_text
Expand Down Expand Up @@ -2630,6 +2642,18 @@ warning:Line 2:9: java.lang.IllegalArgumentException: single-value function enco
emp_no:integer | job_positions:keyword
;

mvKeywordNotEqualsMultiValueConstant
required_capability: fix_mv_constant_comparison_field
FROM employees
| WHERE job_positions != ["Tech Lead" , "Data Scientist", "Senior Team Lead"]
| KEEP emp_no, job_positions
;
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.
warning:Line 2:9: java.lang.IllegalArgumentException: single-value function encountered multi-value

emp_no:integer | job_positions:keyword
;

url_encode sample for docs
required_capability: url_encode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,8 @@ public enum Cap {
* Support for vector similarity functtions pushdown
*/
VECTOR_SIMILARITY_FUNCTIONS_PUSHDOWN(Build.current().isSnapshot()),

FIX_MV_CONSTANT_COMPARISON_FIELD,
// Last capability should still have a comma for fewer merge conflicts when adding new ones :)
// This comment prevents the semicolon from being on the previous capability when Spotless formats the file.
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.xpack.esql.core.expression.Expressions;
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
import org.elasticsearch.xpack.esql.core.expression.Literal;
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
import org.elasticsearch.xpack.esql.core.expression.TypedAttribute;
import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison;
Expand All @@ -47,6 +48,7 @@
import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -329,7 +331,13 @@ public static String formatIncompatibleTypesMessage(DataType leftType, DataType

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