Skip to content

Commit c6d80c6

Browse files
authored
Merge branch '9.0' into backport/9.0/pr-122247
2 parents 0f7eec1 + 7c177dc commit c6d80c6

File tree

90 files changed

+1035
-341
lines changed

Some content is hidden

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

90 files changed

+1035
-341
lines changed

muted-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ tests:
280280
issue: https://github.com/elastic/elasticsearch/issues/122670
281281
- class: org.elasticsearch.telemetry.apm.ApmAgentSettingsIT
282282
issue: https://github.com/elastic/elasticsearch/issues/122546
283+
- class: org.elasticsearch.entitlement.qa.EntitlementsDeniedNonModularIT
284+
issue: https://github.com/elastic/elasticsearch/issues/122569
285+
- class: org.elasticsearch.entitlement.qa.EntitlementsAllowedNonModularIT
286+
issue: https://github.com/elastic/elasticsearch/issues/122568
287+
- class: org.elasticsearch.entitlement.qa.EntitlementsAllowedIT
288+
issue: https://github.com/elastic/elasticsearch/issues/122680
283289

284290
# Examples:
285291
#

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/tree/Source.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public String toString() {
105105
return text + location;
106106
}
107107

108+
/**
109+
* @deprecated Sources created by this can't be correctly deserialized. For use in tests only.
110+
*/
111+
@Deprecated
108112
public static Source synthetic(String text) {
109113
return new Source(Location.EMPTY, text);
110114
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract class AbstractAggregationTestCase extends AbstractFunctionTestCa
6161
* Use if possible, as this method may get updated with new checks in the future.
6262
* </p>
6363
*/
64-
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
64+
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(
6565
List<TestCaseSupplier> suppliers,
6666
boolean entirelyNullPreservesType,
6767
PositionalErrorMessageSupplier positionalErrorMessageSupplier
@@ -74,13 +74,24 @@ protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultCh
7474
);
7575
}
7676

77-
// TODO: Remove and migrate everything to the method with all the parameters
7877
/**
79-
* @deprecated Use {@link #parameterSuppliersFromTypedDataWithDefaultChecks(List, boolean, PositionalErrorMessageSupplier)} instead.
80-
* This method doesn't add all the default checks.
78+
* Converts a list of test cases into a list of parameter suppliers.
79+
* Also, adds a default set of extra test cases.
80+
* <p>
81+
* Use if possible, as this method may get updated with new checks in the future.
82+
* </p>
83+
*
84+
* @param entirelyNullPreservesType See {@link #anyNullIsNull(boolean, List)}
8185
*/
82-
@Deprecated
83-
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(List<TestCaseSupplier> suppliers) {
86+
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(
87+
// TODO remove after removing parameterSuppliersFromTypedDataWithDefaultChecks rename this to that.
88+
List<TestCaseSupplier> suppliers,
89+
boolean entirelyNullPreservesType
90+
) {
91+
return parameterSuppliersFromTypedData(anyNullIsNull(entirelyNullPreservesType, randomizeBytesRefsOffset(suppliers)));
92+
}
93+
94+
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(List<TestCaseSupplier> suppliers) {
8495
return parameterSuppliersFromTypedData(withNoRowsExpectingNull(randomizeBytesRefsOffset(suppliers)));
8596
}
8697

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.LessThan;
6565
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.LessThanOrEqual;
6666
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.NotEquals;
67+
import org.elasticsearch.xpack.esql.io.stream.PlanStreamOutput;
6768
import org.elasticsearch.xpack.esql.optimizer.rules.logical.FoldNull;
6869
import org.elasticsearch.xpack.esql.parser.ExpressionBuilder;
6970
import org.elasticsearch.xpack.esql.planner.Layout;
@@ -102,6 +103,7 @@
102103
import static org.elasticsearch.xpack.esql.EsqlTestUtils.randomLiteral;
103104
import static org.elasticsearch.xpack.esql.EsqlTestUtils.unboundLogicalOptimizerContext;
104105
import static org.elasticsearch.xpack.esql.SerializationTestUtils.assertSerialization;
106+
import static org.elasticsearch.xpack.esql.SerializationTestUtils.serializeDeserialize;
105107
import static org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry.mapParam;
106108
import static org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry.param;
107109
import static org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry.paramWithoutAnnotation;
@@ -331,7 +333,7 @@ protected static String typeErrorMessage(
331333
String ordinal = includeOrdinal ? TypeResolutions.ParamOrdinal.fromIndex(badArgPosition).name().toLowerCase(Locale.ROOT) + " " : "";
332334
String expectedTypeString = expectedTypeSupplier.apply(validPerPosition.get(badArgPosition), badArgPosition);
333335
String name = types.get(badArgPosition).typeName();
334-
return ordinal + "argument of [] must be [" + expectedTypeString + "], found value [" + name + "] type [" + name + "]";
336+
return ordinal + "argument of [source] must be [" + expectedTypeString + "], found value [" + name + "] type [" + name + "]";
335337
}
336338

337339
@FunctionalInterface
@@ -522,7 +524,7 @@ public static Expression deepCopyOfField(String name, DataType type) {
522524
* <strong>except</strong> those that have been marked with {@link TestCaseSupplier.TypedData#forceLiteral()}.
523525
*/
524526
protected final Expression buildFieldExpression(TestCaseSupplier.TestCase testCase) {
525-
return build(testCase.getSource(), testCase.getDataAsFields());
527+
return randomSerializeDeserialize(build(testCase.getSource(), testCase.getDataAsFields()));
526528
}
527529

528530
/**
@@ -531,12 +533,47 @@ protected final Expression buildFieldExpression(TestCaseSupplier.TestCase testCa
531533
* those that have been marked with {@link TestCaseSupplier.TypedData#forceLiteral()}.
532534
*/
533535
protected final Expression buildDeepCopyOfFieldExpression(TestCaseSupplier.TestCase testCase) {
536+
// We don't use `randomSerializeDeserialize()` here as the deep copied fields aren't deserializable right now
534537
return build(testCase.getSource(), testCase.getDataAsDeepCopiedFields());
535538
}
536539

540+
private Expression randomSerializeDeserialize(Expression expression) {
541+
if (randomBoolean()) {
542+
return expression;
543+
}
544+
545+
return serializeDeserializeExpression(expression);
546+
}
547+
548+
/**
549+
* Returns the expression after being serialized and deserialized.
550+
* <p>
551+
* Tests randomly go through this method to ensure that the function retains the same logic after serialization and deserialization.
552+
* </p>
553+
* <p>
554+
* Can be overridden to provide custom serialization and deserialization logic, or disable it if needed.
555+
* </p>
556+
*/
557+
protected Expression serializeDeserializeExpression(Expression expression) {
558+
Expression newExpression = serializeDeserialize(
559+
expression,
560+
PlanStreamOutput::writeNamedWriteable,
561+
in -> in.readNamedWriteable(Expression.class),
562+
testCase.getConfiguration() // The configuration query should be == to the source text of the function for this to work
563+
);
564+
565+
// Fields use synthetic sources, which can't be serialized. So we replace with the originals instead.
566+
var dummyChildren = newExpression.children()
567+
.stream()
568+
.<Expression>map(c -> new Literal(Source.EMPTY, "anything that won't match any test case", c.dataType()))
569+
.toList();
570+
// We first replace them with other unrelated expressions to force a replace, as some replaceChildren() will check for equality
571+
return newExpression.replaceChildrenSameSize(dummyChildren).replaceChildrenSameSize(expression.children());
572+
}
573+
537574
protected final Expression buildLiteralExpression(TestCaseSupplier.TestCase testCase) {
538575
assumeTrue("Data can't be converted to literals", testCase.canGetDataAsLiterals());
539-
return build(testCase.getSource(), testCase.getDataAsLiterals());
576+
return randomSerializeDeserialize(build(testCase.getSource(), testCase.getDataAsLiterals()));
540577
}
541578

542579
public static EvaluatorMapper.ToEvaluator toEvaluator() {
@@ -711,7 +748,7 @@ private static BytesRef randomizeBytesRefOffset(BytesRef bytesRef) {
711748
}
712749

713750
public void testSerializationOfSimple() {
714-
assertSerialization(buildFieldExpression(testCase));
751+
assertSerialization(buildFieldExpression(testCase), testCase.getConfiguration());
715752
}
716753

717754
/**

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractScalarFunctionTestCase.java

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,6 @@
5151
* which can be automatically tested against several scenarios (null handling, concurrency, etc).
5252
*/
5353
public abstract class AbstractScalarFunctionTestCase extends AbstractFunctionTestCase {
54-
55-
/**
56-
* Converts a list of test cases into a list of parameter suppliers.
57-
* Also, adds a default set of extra test cases.
58-
* <p>
59-
* Use if possible, as this method may get updated with new checks in the future.
60-
* </p>
61-
*
62-
* @param entirelyNullPreservesType See {@link #anyNullIsNull(boolean, List)}
63-
* @deprecated use {@link #parameterSuppliersFromTypedDataWithDefaultChecksNoErrors}
64-
* and make a subclass of {@link ErrorsForCasesWithoutExamplesTestCase}.
65-
* It's a <strong>long</strong> faster.
66-
*/
67-
@Deprecated
68-
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
69-
boolean entirelyNullPreservesType,
70-
List<TestCaseSupplier> suppliers,
71-
PositionalErrorMessageSupplier positionalErrorMessageSupplier
72-
) {
73-
return parameterSuppliersFromTypedData(
74-
errorsForCasesWithoutExamples(
75-
anyNullIsNull(entirelyNullPreservesType, randomizeBytesRefsOffset(suppliers)),
76-
positionalErrorMessageSupplier
77-
)
78-
);
79-
}
80-
8154
/**
8255
* Converts a list of test cases into a list of parameter suppliers.
8356
* Also, adds a default set of extra test cases.
@@ -113,30 +86,6 @@ protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultCh
11386
return parameterSuppliersFromTypedData(anyNullIsNull(randomizeBytesRefsOffset(suppliers), nullsExpectedType, evaluatorToString));
11487
}
11588

116-
/**
117-
* Converts a list of test cases into a list of parameter suppliers.
118-
* Also, adds a default set of extra test cases.
119-
* <p>
120-
* Use if possible, as this method may get updated with new checks in the future.
121-
* </p>
122-
*
123-
* @param nullsExpectedType See {@link #anyNullIsNull(List, ExpectedType, ExpectedEvaluatorToString)}
124-
* @param evaluatorToString See {@link #anyNullIsNull(List, ExpectedType, ExpectedEvaluatorToString)}
125-
*/
126-
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
127-
ExpectedType nullsExpectedType,
128-
ExpectedEvaluatorToString evaluatorToString,
129-
List<TestCaseSupplier> suppliers,
130-
PositionalErrorMessageSupplier positionalErrorMessageSupplier
131-
) {
132-
return parameterSuppliersFromTypedData(
133-
errorsForCasesWithoutExamples(
134-
anyNullIsNull(randomizeBytesRefsOffset(suppliers), nullsExpectedType, evaluatorToString),
135-
positionalErrorMessageSupplier
136-
)
137-
);
138-
}
139-
14089
public final void testEvaluate() {
14190
assumeTrue("Can't build evaluator", testCase.canBuildEvaluator());
14291
boolean readFloating = randomBoolean();
@@ -452,8 +401,8 @@ protected static TestCaseSupplier arithmeticExceptionOverflowCase(
452401
evaluator + "[lhs=Attribute[channel=0], rhs=Attribute[channel=1]]",
453402
dataType,
454403
is(nullValue())
455-
).withWarning("Line -1:-1: evaluation of [] failed, treating result as null. Only first 20 failures recorded.")
456-
.withWarning("Line -1:-1: java.lang.ArithmeticException: " + typeNameOverflow)
404+
).withWarning("Line 1:1: evaluation of [source] failed, treating result as null. Only first 20 failures recorded.")
405+
.withWarning("Line 1:1: java.lang.ArithmeticException: " + typeNameOverflow)
457406
);
458407
}
459408
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
import org.elasticsearch.logging.LogManager;
1717
import org.elasticsearch.logging.Logger;
1818
import org.elasticsearch.test.ESTestCase;
19+
import org.elasticsearch.xpack.esql.EsqlTestUtils;
1920
import org.elasticsearch.xpack.esql.core.expression.Expression;
2021
import org.elasticsearch.xpack.esql.core.expression.Literal;
2122
import org.elasticsearch.xpack.esql.core.expression.MapExpression;
23+
import org.elasticsearch.xpack.esql.core.tree.Location;
2224
import org.elasticsearch.xpack.esql.core.tree.Source;
2325
import org.elasticsearch.xpack.esql.core.type.DataType;
2426
import org.elasticsearch.xpack.esql.core.util.NumericUtils;
27+
import org.elasticsearch.xpack.esql.session.Configuration;
2528
import org.elasticsearch.xpack.versionfield.Version;
2629
import org.hamcrest.Matcher;
2730

@@ -54,6 +57,9 @@ public record TestCaseSupplier(String name, List<DataType> types, Supplier<TestC
5457
implements
5558
Supplier<TestCaseSupplier.TestCase> {
5659

60+
public static final Source TEST_SOURCE = new Source(new Location(1, 0), "source");
61+
public static final Configuration TEST_CONFIGURATION = EsqlTestUtils.configuration(TEST_SOURCE.text());
62+
5763
private static final Logger logger = LogManager.getLogger(TestCaseSupplier.class);
5864

5965
/**
@@ -1388,6 +1394,10 @@ public static final class TestCase {
13881394
* The {@link Source} this test case should be run with
13891395
*/
13901396
private final Source source;
1397+
/**
1398+
* The {@link Configuration} this test case should use
1399+
*/
1400+
private final Configuration configuration;
13911401
/**
13921402
* The parameter values and types to pass into the function for this test run
13931403
*/
@@ -1490,7 +1500,8 @@ public static TestCase typeError(List<TypedData> data, String expectedTypeError)
14901500
Object extra,
14911501
boolean canBuildEvaluator
14921502
) {
1493-
this.source = Source.EMPTY;
1503+
this.source = TEST_SOURCE;
1504+
this.configuration = TEST_CONFIGURATION;
14941505
this.data = data;
14951506
this.evaluatorToString = evaluatorToString;
14961507
this.expectedType = expectedType == null ? null : expectedType.noText();
@@ -1510,6 +1521,10 @@ public Source getSource() {
15101521
return source;
15111522
}
15121523

1524+
public Configuration getConfiguration() {
1525+
return configuration;
1526+
}
1527+
15131528
public List<TypedData> getData() {
15141529
return data;
15151530
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.aggregate;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.core.type.DataType;
13+
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
14+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
15+
import org.hamcrest.Matcher;
16+
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import static org.hamcrest.Matchers.equalTo;
21+
22+
public class AvgErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(AvgTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new Avg(source, args.get(0));
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(typeErrorMessage(false, validPerPosition, signature, (v, p) -> "numeric except unsigned_long or counter types"));
36+
}
37+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/AvgTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static Iterable<Object[]> parameters() {
5353
)
5454
);
5555

56-
return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers, true, (v, p) -> "numeric except unsigned_long or counter types");
56+
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
5757
}
5858

5959
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountDistinctTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public static Iterable<Object[]> parameters() {
9393
}
9494

9595
// "No rows" expects 0 here instead of null
96-
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
9796
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
9897
}
9998

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/CountTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public static Iterable<Object[]> parameters() {
8282
}
8383

8484
// "No rows" expects 0 here instead of null
85-
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
8685
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
8786
}
8887

0 commit comments

Comments
 (0)