Skip to content

Commit 1370f6e

Browse files
authored
ESQL: Even more test type error testing movements (elastic#121321) (elastic#122829)
Manual 9.0 backport of elastic#121321
1 parent 777d5d0 commit 1370f6e

Some content is hidden

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

47 files changed

+692
-127
lines changed

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/AbstractScalarFunctionTestCase.java

Lines changed: 0 additions & 51 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();
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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 MaxErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(MaxTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new Max(source, args.get(0));
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(
36+
typeErrorMessage(false, validPerPosition, signature, (v, p) -> "representable except unsigned_long and spatial types")
37+
);
38+
}
39+
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ public static Iterable<Object[]> parameters() {
157157
)
158158
);
159159

160-
return parameterSuppliersFromTypedDataWithDefaultChecks(
161-
suppliers,
162-
false,
163-
(v, p) -> "representable except unsigned_long and spatial types"
164-
);
160+
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, false);
165161
}
166162

167163
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static Iterable<Object[]> parameters() {
3939
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true)
4040
).flatMap(List::stream).map(MedianAbsoluteDeviationTests::makeSupplier).toList();
4141

42-
return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
42+
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
4343
}
4444

4545
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static Iterable<Object[]> parameters() {
7373
)
7474
);
7575

76-
return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
76+
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
7777
}
7878

7979
@Override

0 commit comments

Comments
 (0)