Skip to content

Commit 002773a

Browse files
committed
clean up non-parameterized tests in the wrong place
1 parent 89d84da commit 002773a

File tree

6 files changed

+181
-131
lines changed

6 files changed

+181
-131
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
12+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
13+
import org.elasticsearch.xpack.esql.core.expression.Literal;
14+
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
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 EndsWithStaticTests extends ESTestCase {
27+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
28+
EndsWith function = new EndsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
29+
30+
ESTestCase.assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
31+
}
32+
33+
public void testLuceneQuery_NonFoldableSuffix_NonTranslatable() {
34+
EndsWith function = new EndsWith(
35+
Source.EMPTY,
36+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
37+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true))
38+
);
39+
40+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
41+
}
42+
43+
public void testLuceneQuery_NonFoldableSuffix_Translatable() {
44+
EndsWith function = new EndsWith(
45+
Source.EMPTY,
46+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
47+
Literal.keyword(Source.EMPTY, "a*b?c\\")
48+
);
49+
50+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
51+
52+
Query query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
53+
54+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "*a\\*b\\?c\\\\", false, false)));
55+
}
56+
}

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,56 @@
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.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
12+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
13+
import org.elasticsearch.xpack.esql.core.expression.Literal;
14+
import org.elasticsearch.xpack.esql.core.querydsl.query.WildcardQuery;
15+
import org.elasticsearch.xpack.esql.core.tree.Source;
16+
import org.elasticsearch.xpack.esql.core.type.DataType;
17+
import org.elasticsearch.xpack.esql.core.type.EsField;
18+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
19+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
20+
21+
import java.util.Map;
22+
23+
import static org.hamcrest.Matchers.equalTo;
24+
25+
public class StartsWithStaticTests extends ESTestCase {
26+
27+
public void testLuceneQuery_AllLiterals_NonTranslatable() {
28+
var function = new StartsWith(Source.EMPTY, Literal.keyword(Source.EMPTY, "test"), Literal.keyword(Source.EMPTY, "test"));
29+
30+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
31+
}
32+
33+
public void testLuceneQuery_NonFoldablePrefix_NonTranslatable() {
34+
var function = new StartsWith(
35+
Source.EMPTY,
36+
new FieldAttribute(Source.EMPTY, "field", new EsField("field", DataType.KEYWORD, Map.of(), true)),
37+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true))
38+
);
39+
40+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.NO));
41+
}
42+
43+
public void testLuceneQuery_NonFoldablePrefix_Translatable() {
44+
var function = new StartsWith(
45+
Source.EMPTY,
46+
new FieldAttribute(Source.EMPTY, "field", new EsField("prefix", DataType.KEYWORD, Map.of(), true)),
47+
Literal.keyword(Source.EMPTY, "a*b?c\\")
48+
);
49+
50+
assertThat(function.translatable(LucenePushdownPredicates.DEFAULT), equalTo(TranslationAware.Translatable.YES));
51+
52+
var query = function.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
53+
54+
assertThat(query, equalTo(new WildcardQuery(Source.EMPTY, "field", "a\\*b\\?c\\\\*", false, false)));
55+
}
56+
}

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

Lines changed: 0 additions & 37 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;
@@ -67,33 +59,4 @@ protected Expression build(Source source, List<Expression> args) {
6759
return new StartsWith(source, args.get(0), args.get(1));
6860
}
6961

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-
}
9962
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.FieldAttribute;
12+
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
13+
import org.elasticsearch.xpack.esql.core.expression.Literal;
14+
import org.elasticsearch.xpack.esql.core.querydsl.query.TermsQuery;
15+
import org.elasticsearch.xpack.esql.core.tree.Source;
16+
import org.elasticsearch.xpack.esql.core.type.DataType;
17+
import org.elasticsearch.xpack.esql.core.type.EsField;
18+
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
19+
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
20+
21+
import java.util.Arrays;
22+
import java.util.Map;
23+
import java.util.Set;
24+
25+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.L;
26+
import static org.elasticsearch.xpack.esql.core.expression.Literal.NULL;
27+
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
28+
29+
public class InStaticTests extends ESTestCase {
30+
private static final Literal ONE = L(1);
31+
private static final Literal TWO = L(2);
32+
private static final Literal THREE = L(3);
33+
34+
public void testInWithContainedValue() {
35+
In in = new In(EMPTY, TWO, Arrays.asList(ONE, TWO, THREE));
36+
assertTrue((Boolean) in.fold(FoldContext.small()));
37+
}
38+
39+
public void testInWithNotContainedValue() {
40+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, TWO));
41+
assertFalse((Boolean) in.fold(FoldContext.small()));
42+
}
43+
44+
public void testHandleNullOnLeftValue() {
45+
In in = new In(EMPTY, NULL, Arrays.asList(ONE, TWO, THREE));
46+
assertNull(in.fold(FoldContext.small()));
47+
in = new In(EMPTY, NULL, Arrays.asList(ONE, NULL, THREE));
48+
assertNull(in.fold(FoldContext.small()));
49+
50+
}
51+
52+
public void testHandleNullsOnRightValue() {
53+
In in = new In(EMPTY, THREE, Arrays.asList(ONE, NULL, THREE));
54+
assertTrue((Boolean) in.fold(FoldContext.small()));
55+
in = new In(EMPTY, ONE, Arrays.asList(TWO, NULL, THREE));
56+
assertNull(in.fold(FoldContext.small()));
57+
}
58+
59+
public void testConvertedNull() {
60+
In in = new In(
61+
EMPTY,
62+
new FieldAttribute(Source.EMPTY, "field", new EsField("suffix", DataType.KEYWORD, Map.of(), true)),
63+
Arrays.asList(ONE, new Literal(Source.EMPTY, null, randomFrom(DataType.types())), THREE)
64+
);
65+
var query = in.asQuery(LucenePushdownPredicates.DEFAULT, TranslatorHandler.TRANSLATOR_HANDLER);
66+
assertEquals(new TermsQuery(EMPTY, "field", Set.of(1, 3)), query);
67+
}
68+
69+
}

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;
25-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
26-
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
2720
import org.junit.AfterClass;
2821

2922
import java.util.ArrayList;
30-
import java.util.Arrays;
3123
import java.util.List;
3224
import java.util.Locale;
33-
import java.util.Map;
34-
import java.util.Set;
3525
import java.util.function.Supplier;
3626
import java.util.stream.IntStream;
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;
@@ -54,49 +41,6 @@ public InTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSup
5441
this.testCase = testCaseSupplier.get();
5542
}
5643

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

0 commit comments

Comments
 (0)