Skip to content

Commit c40c5a6

Browse files
authored
ESQL: Fix functions emitting warnings with no source (#122821)
Fixes #122588 - Replaced `Source.EMPTY.writeTo(out)` to `source().writeTo(out)` in functions emitting warnings - Did the same on all aggs, as Top emits an error on type resolution. This is not a bug, as type resolution errors should only happen in the coordinator. Another option would be changing Top to not generate that error there, and make it implement instead `PostAnalysisVerificationAware` - In some cases, we don't even serialize an empty source. So I had to add a new `TransportVersion` to do so - As an special case, `ToLower` and `ToUpper` weren't serializing a source, but they don't emit warnings. As they were the only remaining functions not serializing the source, I added it there too
1 parent cae7f0a commit c40c5a6

File tree

49 files changed

+230
-216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+230
-216
lines changed

docs/changelog/122821.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122821
2+
summary: Fix functions emitting warnings with no source
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 122588

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ static TransportVersion def(int id) {
203203
public static final TransportVersion RERANKER_FAILURES_ALLOWED = def(9_013_0_00);
204204
public static final TransportVersion VOYAGE_AI_INTEGRATION_ADDED = def(9_014_0_00);
205205
public static final TransportVersion BYTE_SIZE_VALUE_ALWAYS_USES_BYTES = def(9_015_0_00);
206+
public static final TransportVersion ESQL_SERIALIZE_SOURCE_FUNCTIONS_WARNINGS = def(9_016_0_00);
206207

207208
/*
208209
* STOP! READ THIS FIRST! No, really,

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ emp_no:integer | is_rehired:boolean | a1:boolean
287287
10005 | [false,false,false,true] | false
288288
;
289289

290+
mvSliceWarnings
291+
required_capability: functions_source_serialization_warnings
292+
293+
FROM employees
294+
| SORT first_name ASC
295+
| EVAL
296+
start = CASE(first_name == "Alejandro", 1, 0),
297+
end = CASE(first_name == "Alejandro", 0, 1),
298+
result = MV_SLICE(is_rehired, start, end)
299+
| KEEP first_name, result
300+
| LIMIT 1
301+
;
302+
303+
warning:Line 6:10: evaluation of [MV_SLICE(is_rehired, start, end)] failed, treating result as null. Only first 20 failures recorded.
304+
warning:Line 6:10: org.elasticsearch.xpack.esql.core.InvalidArgumentException: Start offset is greater than end offset
305+
306+
first_name:keyword | result:boolean
307+
Alejandro | null
308+
;
309+
290310
values
291311
required_capability: agg_values
292312

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,27 @@ date1:date | dd_ms:integer
366366
2023-12-02T11:00:00.000Z | 1000
367367
;
368368

369+
dateDiffTestWarnings
370+
required_capability: functions_source_serialization_warnings
371+
372+
FROM employees
373+
| WHERE first_name IN ("Alejandro", "Mary")
374+
| SORT first_name ASC
375+
| EVAL date = TO_DATETIME("2023-12-02T11:00:00.000Z")
376+
| EVAL dd_ms = DATE_DIFF(first_name, date, date)
377+
| KEEP date, dd_ms
378+
| LIMIT 2
379+
;
380+
381+
warning:Line 5:16: evaluation of [DATE_DIFF(first_name, date, date)] failed, treating result as null. Only first 20 failures recorded.
382+
warning:Line 5:16: java.lang.IllegalArgumentException: A value of [YEAR, QUARTER, MONTH, DAYOFYEAR, DAY, WEEK, WEEKDAY, HOUR, MINUTE, SECOND, MILLISECOND, MICROSECOND, NANOSECOND] or their aliases is required; received [Alejandro]
383+
warning:Line 5:16: java.lang.IllegalArgumentException: Received value [Mary] is not valid date part to add; did you mean [day]?
384+
385+
date:date | dd_ms:integer
386+
2023-12-02T11:00:00.000Z | null
387+
2023-12-02T11:00:00.000Z | null
388+
;
389+
369390
evalDateDiffMonthAsWhole0Months#[skip:-8.14.1, reason:omitting millis/timezone not allowed before 8.14]
370391

371392
ROW from=TO_DATETIME("2023-12-31T23:59:59.999Z"), to=TO_DATETIME("2024-01-01T00:00:00")

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,33 @@ mvsum:unsigned_long
10091009
null
10101010
;
10111011

1012+
mvSumOverflowOnNode
1013+
required_capability: functions_source_serialization_warnings
1014+
1015+
FROM employees
1016+
| SORT first_name ASC
1017+
| EVAL
1018+
ints = CASE(first_name == "Alejandro", [0, 1, 2147483647], 0),
1019+
longs = CASE(first_name == "Alejandro", [0, 1, 9223372036854775807], 0),
1020+
ulongs = CASE(first_name == "Alejandro", [0, 1, 18446744073709551615], 0),
1021+
intsResult = mv_sum(ints),
1022+
longsResult = mv_sum(longs),
1023+
ulongsResult = mv_sum(ulongs)
1024+
| KEEP first_name, intsResult, longsResult, ulongsResult
1025+
| LIMIT 1
1026+
;
1027+
1028+
warning:Line 7:14: evaluation of [mv_sum(ints)] failed, treating result as null. Only first 20 failures recorded.
1029+
warning:Line 7:14: java.lang.ArithmeticException: integer overflow
1030+
warning:Line 8:15: evaluation of [mv_sum(longs)] failed, treating result as null. Only first 20 failures recorded.
1031+
warning:Line 8:15: java.lang.ArithmeticException: long overflow
1032+
warning:Line 9:16: evaluation of [mv_sum(ulongs)] failed, treating result as null. Only first 20 failures recorded.
1033+
warning:Line 9:16: java.lang.ArithmeticException: unsigned_long overflow
1034+
1035+
first_name:keyword | intsResult:integer | longsResult:long | ulongsResult:unsigned_long
1036+
Alejandro | null | null | null
1037+
;
1038+
10121039
e
10131040
// tag::e[]
10141041
ROW E()

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,25 @@ Gatewayinstances|Gateway instances
10681068
null |null
10691069
;
10701070

1071+
replaceWarnings
1072+
required_capability: functions_source_serialization_warnings
1073+
1074+
FROM employees
1075+
| SORT first_name ASC
1076+
| EVAL
1077+
regex = CASE(first_name == "Alejandro", "(", ""),
1078+
result = replace(first_name, regex, "")
1079+
| KEEP first_name, result
1080+
| LIMIT 1
1081+
;
1082+
1083+
warningRegex:Line 5:10: evaluation of \[replace\(first_name, regex, \\"\\"\)\] failed, treating result as null. Only first 20 failures recorded.
1084+
warningRegex:Line 5:10: java.util.regex.PatternSyntaxException: Unclosed group near index 1(%0D)?%0A\(
1085+
1086+
first_name:keyword | result:keyword
1087+
Alejandro | null
1088+
;
1089+
10711090
left
10721091
// tag::left[]
10731092
FROM employees

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ public enum Cap {
204204
*/
205205
FN_ROUND_UL_FIXES,
206206

207+
/**
208+
* Fixes for multiple functions not serializing their source, and emitting warnings with wrong line number and text.
209+
*/
210+
FUNCTIONS_SOURCE_SERIALIZATION_WARNINGS,
211+
207212
/**
208213
* All functions that take TEXT should never emit TEXT, only KEYWORD. #114334
209214
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/AggregateFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected AggregateFunction(StreamInput in) throws IOException {
6969

7070
@Override
7171
public final void writeTo(StreamOutput out) throws IOException {
72-
Source.EMPTY.writeTo(out);
72+
source().writeTo(out);
7373
out.writeNamedWriteable(field);
7474
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
7575
out.writeNamedWriteable(filter);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private DateDiff(StreamInput in) throws IOException {
197197

198198
@Override
199199
public void writeTo(StreamOutput out) throws IOException {
200-
Source.EMPTY.writeTo(out);
200+
source().writeTo(out);
201201
out.writeNamedWriteable(unit);
202202
out.writeNamedWriteable(startTimestamp);
203203
out.writeNamedWriteable(endTimestamp);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected AbstractMultivalueFunction(StreamInput in) throws IOException {
4141

4242
@Override
4343
public final void writeTo(StreamOutput out) throws IOException {
44-
Source.EMPTY.writeTo(out);
44+
source().writeTo(out);
4545
out.writeNamedWriteable(field);
4646
}
4747

0 commit comments

Comments
 (0)