Skip to content

Commit 5bee7e7

Browse files
Clean up non-parameterized tests in the wrong place (elastic#131049) (elastic#131331)
* Clean up non-parameterized tests in the wrong place (elastic#131049) In the course of other work I found a few places where we were creating non-parameterized tests from within the parameterized test drivers for a few ESQL functions. This causes those tests to be run for every parameter combination, even though the tests themselves do not change anything, resulting in a lot of extra test overhead for no additional coverage. I cleaned up three classes: EndsWithTests ran 832 tests before this, and now runs 640 tests StartsWithTests ran 208 before this, and now runs 160 InTests ran 168 before this, and now runs 28 So overall, that's 369 redundant test runs removed (including the fact that the 11 tests I moved still run once in their new classes), and further savings if we later expand those parameterized tests. * Fixup --------- Co-authored-by: Mark Tozzi <[email protected]>
1 parent 7bd8aaa commit 5bee7e7

File tree

6 files changed

+171
-132
lines changed

6 files changed

+171
-132
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.scalar.string;
9+
10+
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
13+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
16+
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
17+
import org.elasticsearch.xpack.esql.core.tree.Source;
18+
import org.elasticsearch.xpack.esql.core.type.DataType;
19+
import org.elasticsearch.xpack.esql.core.type.EsField;
20+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
21+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
22+
23+
import java.util.Map;
24+
25+
import static org.hamcrest.Matchers.equalTo;
26+
27+
public class EndsWithStaticTests extends ESTestCase {
28+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
29+
EndsWith function = new EndsWith(
30+
Source.EMPTY,
31+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD),
32+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD)
33+
);
34+
35+
ESTestCase.assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
36+
}
37+
38+
public void testLuceneQuery_NonFoldableSuffix_NonTranslatable() {
39+
EndsWith function = new EndsWith(
40+
Source.EMPTY,
41+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
42+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true))
43+
);
44+
45+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
46+
}
47+
48+
public void testLuceneQuery_NonFoldableSuffix_Translatable() {
49+
EndsWith function = new EndsWith(
50+
Source.EMPTY,
51+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
52+
new Literal(Source.EMPTY, new BytesRef("a*b?c\\"), DataType.KEYWORD)
53+
);
54+
55+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
56+
57+
Query query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
58+
59+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "*a\\*b\\?c\\\\", false, false)));
60+
}
61+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/EndsWithTests.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,15 @@
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

1313
import org.apache.lucene.util.BytesRef;
14-
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
16-
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
17-
import org.elasticsearch.xpack.esql.core.expression.Literal;
18-
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
1915
import org.elasticsearch.xpack.esql.core.tree.Source;
2016
import org.elasticsearch.xpack.esql.core.type.DataType;
21-
import org.elasticsearch.xpack.esql.core.type.EsField;
2217
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
2318
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
24-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
25-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2619
import org.hamcrest.Matcher;
2720

2821
import java.util.LinkedList;
2922
import java.util.List;
30-
import java.util.Map;
3123
import java.util.function.Supplier;
3224

3325
import static org.hamcrest.Matchers.equalTo;
@@ -106,34 +98,4 @@ private static TestCaseSupplier.TestCase testCase(
10698
protected Expression build(Source source, List<Expression> args) {
10799
return new EndsWith(source, args.get(0), args.get(1));
108100
}
109-
110-
public void testLuceneQuery_AllLiterals_NonTranslatable() {
111-
var function = new EndsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
112-
113-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
114-
}
115-
116-
public void testLuceneQuery_NonFoldableSuffix_NonTranslatable() {
117-
var function = new EndsWith(
118-
Source.EMPTY,
119-
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
120-
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true))
121-
);
122-
123-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
124-
}
125-
126-
public void testLuceneQuery_NonFoldableSuffix_Translatable() {
127-
var function = new EndsWith(
128-
Source.EMPTY,
129-
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
130-
Literal.keyword(Source.EMPTY, "a*b?c\\")
131-
);
132-
133-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
134-
135-
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
136-
137-
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "*a\\*b\\?c\\\\", false, false)));
138-
}
139101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.scalar.string;
9+
10+
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
13+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
16+
import org.elasticsearch.xpack.esql.core.tree.Source;
17+
import org.elasticsearch.xpack.esql.core.type.DataType;
18+
import org.elasticsearch.xpack.esql.core.type.EsField;
19+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
20+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
21+
22+
import java.util.Map;
23+
24+
import static org.hamcrest.Matchers.equalTo;
25+
26+
public class StartsWithStaticTests extends ESTestCase {
27+
28+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
29+
var function = new StartsWith(
30+
Source.EMPTY,
31+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD),
32+
new Literal(Source.EMPTY, new BytesRef("test"), DataType.KEYWORD)
33+
);
34+
35+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
36+
}
37+
38+
public void testLuceneQuery_NonFoldablePrefix_NonTranslatable() {
39+
var function = new StartsWith(
40+
Source.EMPTY,
41+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
42+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true))
43+
);
44+
45+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
46+
}
47+
48+
public void testLuceneQuery_NonFoldablePrefix_Translatable() {
49+
var function = new StartsWith(
50+
Source.EMPTY,
51+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true)),
52+
new Literal(Source.EMPTY, new BytesRef("a*b?c\\"), DataType.KEYWORD)
53+
);
54+
55+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
56+
57+
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
58+
59+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "a\\*b\\?c\\\\*", false, false)));
60+
}
61+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/StartsWithTests.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

1313
import org.apache.lucene.util.BytesRef;
14-
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
16-
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
17-
import org.elasticsearch.xpack.esql.core.expression.Literal;
18-
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
1915
import org.elasticsearch.xpack.esql.core.tree.Source;
2016
import org.elasticsearch.xpack.esql.core.type.DataType;
21-
import org.elasticsearch.xpack.esql.core.type.EsField;
2217
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
2318
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
24-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
25-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2619

2720
import java.util.ArrayList;
2821
import java.util.List;
29-
import java.util.Map;
3022
import java.util.function.Supplier;
3123

3224
import static org.hamcrest.Matchers.equalTo;
@@ -66,34 +58,4 @@ public static Iterable<Object[]> parameters() {
6658
protected Expression build(Source source, List<Expression> args) {
6759
return new StartsWith(source, args.get(0), args.get(1));
6860
}
69-
70-
public void testLuceneQuery_AllLiterals_NonTranslatable() {
71-
var function = new StartsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
72-
73-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
74-
}
75-
76-
public void testLuceneQuery_NonFoldablePrefix_NonTranslatable() {
77-
var function = new StartsWith(
78-
Source.EMPTY,
79-
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
80-
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true))
81-
);
82-
83-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
84-
}
85-
86-
public void testLuceneQuery_NonFoldablePrefix_Translatable() {
87-
var function = new StartsWith(
88-
Source.EMPTY,
89-
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true)),
90-
Literal.keyword(Source.EMPTY, "a*b?c\\")
91-
);
92-
93-
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
94-
95-
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
96-
97-
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "a\\*b\\?c\\\\*", false, false)));
98-
}
9961
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.predicate.operator.comparison;
9+
10+
import org.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
12+
import org.elasticsearch.xpack.esql.core.expression.Literal;
13+
14+
import java.util.Arrays;
15+
16+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.L;
17+
import static org.elasticsearch.xpack.esql.core.expression.Literal.NULL;
18+
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
19+
20+
public class InStaticTests extends ESTestCase {
21+
private static final Literal ONE = L(1);
22+
private static final Literal TWO = L(2);
23+
private static final Literal THREE = L(3);
24+
25+
public void testInWithContainedValue() {
26+
In in = new In(EMPTY, TWO, Arrays.asList(ONE, TWO, THREE));
27+
assertTrue((Boolean) in.fold(FoldContext.small()));
28+
}
29+
30+
public void testInWithNotContainedValue() {
31+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, TWO));
32+
assertFalse((Boolean) in.fold(FoldContext.small()));
33+
}
34+
35+
public void testHandleNullOnLeftValue() {
36+
In in = new In(EMPTY, NULL, Arrays.asList(ONE, TWO, THREE));
37+
assertNull(in.fold(FoldContext.small()));
38+
in = new In(EMPTY, NULL, Arrays.asList(ONE, NULL, THREE));
39+
assertNull(in.fold(FoldContext.small()));
40+
41+
}
42+
43+
public void testHandleNullsOnRightValue() {
44+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, NULL, THREE));
45+
assertTrue((Boolean) in.fold(FoldContext.small()));
46+
in = new In(EMPTY, ONE, Arrays.asList(TWO, NULL, THREE));
47+
assertNull(in.fold(FoldContext.small()));
48+
}
49+
}

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,19 @@
1313
import org.elasticsearch.geo.GeometryTestUtils;
1414
import org.elasticsearch.geo.ShapeTestUtils;
1515
import org.elasticsearch.xpack.esql.core.expression.Expression;
16-
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
17-
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
18-
import org.elasticsearch.xpack.esql.core.expression.Literal;
19-
import org.elasticsearch.xpack.esql.core.querydsl.query.TermsQuery;
2016
import org.elasticsearch.xpack.esql.core.tree.Source;
2117
import org.elasticsearch.xpack.esql.core.type.DataType;
22-
import org.elasticsearch.xpack.esql.core.type.EsField;
2318
import org.elasticsearch.xpack.esql.expression.function.AbstractFunctionTestCase;
2419
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
2520
import org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLikeTests;
26-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
27-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2821
import org.junit.AfterClass;
2922

3023
import java.io.IOException;
3124
import java.util.ArrayList;
32-
import java.util.Arrays;
3325
import java.util.List;
34-
import java.util.Map;
35-
import java.util.Set;
3626
import java.util.function.Supplier;
3727

38-
import static org.elasticsearch.xpack.esql.EsqlTestUtils.of;
3928
import static org.elasticsearch.xpack.esql.EsqlTestUtils.randomLiteral;
40-
import static org.elasticsearch.xpack.esql.core.expression.Literal.NULL;
41-
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
4229
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_POINT;
4330
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_SHAPE;
4431
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
@@ -53,49 +40,6 @@ public InTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSup
5340
this.testCase = testCaseSupplier.get();
5441
}
5542

56-
private static final Literal ONE = L(1);
57-
private static final Literal TWO = L(2);
58-
private static final Literal THREE = L(3);
59-
60-
public void testInWithContainedValue() {
61-
In in = new In(EMPTY, TWO, Arrays.asList(ONE, TWO, THREE));
62-
assertTrue((Boolean) in.fold(FoldContext.small()));
63-
}
64-
65-
public void testInWithNotContainedValue() {
66-
In in = new In(EMPTY, THREE, Arrays.asList(ONE, TWO));
67-
assertFalse((Boolean) in.fold(FoldContext.small()));
68-
}
69-
70-
public void testHandleNullOnLeftValue() {
71-
In in = new In(EMPTY, NULL, Arrays.asList(ONE, TWO, THREE));
72-
assertNull(in.fold(FoldContext.small()));
73-
in = new In(EMPTY, NULL, Arrays.asList(ONE, NULL, THREE));
74-
assertNull(in.fold(FoldContext.small()));
75-
76-
}
77-
78-
public void testHandleNullsOnRightValue() {
79-
In in = new In(EMPTY, THREE, Arrays.asList(ONE, NULL, THREE));
80-
assertTrue((Boolean) in.fold(FoldContext.small()));
81-
in = new In(EMPTY, ONE, Arrays.asList(TWO, NULL, THREE));
82-
assertNull(in.fold(FoldContext.small()));
83-
}
84-
85-
private static Literal L(Object value) {
86-
return of(EMPTY, value);
87-
}
88-
89-
public void testConvertedNull() {
90-
In in = new In(
91-
EMPTY,
92-
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
93-
Arrays.asList(ONE, new Literal(Source.EMPTY, null, randomFrom(DataType.types())), THREE)
94-
);
95-
var query = in.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
96-
assertEquals(new TermsQuery(EMPTY, "field", Set.of(1, 3)), query);
97-
}
98-
9943
@ParametersFactory
10044
public static Iterable<Object[]> parameters() {
10145
List<TestCaseSupplier> suppliers = new ArrayList<>();

0 commit comments

Comments
 (0)