Skip to content

Commit 9758344

Browse files
Clean up and fix UTs
1 parent 6d9ea08 commit 9758344

File tree

16 files changed

+36
-669
lines changed

16 files changed

+36
-669
lines changed

patch.patch

Lines changed: 0 additions & 626 deletions
This file was deleted.

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,13 @@ public void testLikeIndex() throws Exception {
431431
}
432432

433433
public void testLikeIndexLegacySettingNoResults() throws Exception {
434-
boolean isSupported = clusterHasCapability("POST", "/_query", List.of(), List.of("like_on_index_fields")).orElse(false);
435-
if (isSupported == false) {
436-
// we require that the admin client supports the like_on_index_fields capability
437-
// otherwise we will get an error when trying to toggle the setting
438-
// the remote client does not have to support it
439-
logger.info("--> skipping testLikeIndexLegacySettingNoResults, due to missing capability");
440-
return;
441-
}
442-
try (ClusterSettingToggle ignored = new ClusterSettingToggle(adminClient(), "esql.query.string_like_on_index", false, true)) {
434+
// the feature is completely supported if both local and remote clusters support it
435+
assumeTrue("not supported", clusterHasCapability("POST", "/_query", List.of(), List.of("like_on_index_fields")).orElse(false));
436+
try (
437+
ClusterSettingToggle ignored = new ClusterSettingToggle(adminClient(), "esql.query.string_like_on_index", false, true);
438+
RestClient remoteClient = remoteClusterClient();
439+
ClusterSettingToggle ignored2 = new ClusterSettingToggle(remoteClient, "esql.query.string_like_on_index", false, true)
440+
) {
443441
// test code with the setting changed
444442
boolean includeCCSMetadata = includeCCSMetadata();
445443
Map<String, Object> result = run("""
@@ -456,14 +454,10 @@ public void testLikeIndexLegacySettingNoResults() throws Exception {
456454
}
457455

458456
public void testLikeIndexLegacySettingResults() throws Exception {
459-
boolean isSupported = clusterHasCapability("POST", "/_query", List.of(), List.of("like_on_index_fields")).orElse(false);
460-
if (isSupported == false) {
461-
// we require that the admin client supports the like_on_index_fields capability
462-
// otherwise we will get an error when trying to toggle the setting
463-
// the remote client does not have to support it
464-
logger.info("--> skipping testLikeIndexLegacySettingNoResults, due to missing capability");
465-
return;
466-
}
457+
// we require that the admin client supports the like_on_index_fields capability
458+
// otherwise we will get an error when trying to toggle the setting
459+
// the remote client does not have to support it
460+
assumeTrue("not supported", clusterHasCapability("POST", "/_query", List.of(), List.of("like_on_index_fields")).orElse(false));
467461
try (ClusterSettingToggle ignored = new ClusterSettingToggle(adminClient(), "esql.query.string_like_on_index", false, true)) {
468462
boolean includeCCSMetadata = includeCCSMetadata();
469463
Map<String, Object> result = run("""

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/ConfigurationTestUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public static Configuration randomConfiguration(String query, Map<String, Map<St
7272
profile,
7373
tables,
7474
System.nanoTime(),
75-
false,
76-
true // stringLikeOnIndex, default to true for tests
75+
false
7776
);
7877
}
7978

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ public static Configuration configuration(QueryPragmas pragmas, String query) {
429429
false,
430430
TABLES,
431431
System.nanoTime(),
432-
false,
433-
true // stringLikeOnIndex, default to true for tests
432+
false
434433
);
435434
}
436435

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/ExpressionQueryBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.xpack.esql.core.expression.Expression;
2525

2626
import java.io.IOException;
27-
import java.io.UnsupportedEncodingException;
2827
import java.util.Objects;
2928

3029
import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE;
@@ -88,7 +87,10 @@ public String getWriteableName() {
8887

8988
@Override
9089
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
91-
throw new UnsupportedEncodingException("ExpressionQueryBuilder does not support doXContent");
90+
builder.startObject(ENTRY.name); // Use the appropriate query name
91+
builder.field("field", fieldName);
92+
builder.field("expression", expression.toString());
93+
builder.endObject();
9294
}
9395

9496
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import org.elasticsearch.xpack.esql.planner.PlannerUtils;
8989
import org.elasticsearch.xpack.esql.planner.TestPhysicalOperationProviders;
9090
import org.elasticsearch.xpack.esql.planner.mapper.Mapper;
91+
import org.elasticsearch.xpack.esql.plugin.EsqlFlags;
9192
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
9293
import org.elasticsearch.xpack.esql.session.Configuration;
9394
import org.elasticsearch.xpack.esql.session.EsqlSession;
@@ -715,7 +716,7 @@ void executeSubPlan(
715716
var searchStats = new DisabledSearchStats();
716717
var logicalTestOptimizer = new LocalLogicalPlanOptimizer(new LocalLogicalOptimizerContext(configuration, foldCtx, searchStats));
717718
var physicalTestOptimizer = new TestLocalPhysicalPlanOptimizer(
718-
new LocalPhysicalOptimizerContext(configuration, foldCtx, searchStats)
719+
new LocalPhysicalOptimizerContext(new EsqlFlags(true), configuration, foldCtx, searchStats)
719720
);
720721

721722
var csvDataNodePhysicalPlan = PlannerUtils.localPlan(dataNodePlan, logicalTestOptimizer, physicalTestOptimizer);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ private static Configuration randomConfiguration() {
5555
randomBoolean(),
5656
Map.of(),
5757
System.nanoTime(),
58-
randomBoolean(),
59-
true
58+
randomBoolean()
6059
);
6160
}
6261
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private Configuration randomLocaleConfig() {
7171
false,
7272
Map.of(),
7373
System.nanoTime(),
74-
randomBoolean(),
75-
true
74+
randomBoolean()
7675
);
7776
}
7877

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private Configuration randomLocaleConfig() {
7171
false,
7272
Map.of(),
7373
System.nanoTime(),
74-
randomBoolean(),
75-
true
74+
randomBoolean()
7675
);
7776
}
7877

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
2626
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.WildcardLikeList;
2727
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
28+
import org.elasticsearch.xpack.esql.plugin.EsqlFlags;
2829

2930
import java.util.ArrayList;
3031
import java.util.List;
@@ -104,15 +105,15 @@ static Expression buildWildcardLikeList(Source source, List<Expression> args) {
104105
public void testNotPushableOverCanMatch() {
105106
TranslationAware translatable = (TranslationAware) buildFieldExpression(testCase);
106107
assertThat(
107-
translatable.translatable(LucenePushdownPredicates.forCanMatch(V_8_17_0, EsqlTestUtils.TEST_CFG)).finish(),
108+
translatable.translatable(LucenePushdownPredicates.forCanMatch(V_8_17_0, new EsqlFlags(true))).finish(),
108109
equalTo(TranslationAware.FinishedTranslatable.NO)
109110
);
110111
}
111112

112113
public void testPushable() {
113114
TranslationAware translatable = (TranslationAware) buildFieldExpression(testCase);
114115
assertThat(
115-
translatable.translatable(LucenePushdownPredicates.from(new EsqlTestUtils.TestSearchStats(), EsqlTestUtils.TEST_CFG)).finish(),
116+
translatable.translatable(LucenePushdownPredicates.from(new EsqlTestUtils.TestSearchStats(), new EsqlFlags(true))).finish(),
116117
equalTo(TranslationAware.FinishedTranslatable.YES)
117118
);
118119
}

0 commit comments

Comments
 (0)