From 3f13c4a88184e16b7b84d219c1870c3dd1117a2c Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Wed, 27 Mar 2024 18:59:59 +0100 Subject: [PATCH] WIP: add lang version to ITs --- .../test/esql/qa/action/CoreEsqlActionIT.java | 8 +++- .../xpack/esql/EsqlAsyncSecurityIT.java | 1 + .../xpack/esql/EsqlSecurityIT.java | 1 + .../xpack/esql/ccq/MultiClusterSpecIT.java | 8 ++++ .../xpack/esql/ccq/MultiClustersIT.java | 2 +- .../xpack/esql/qa/multi_node/EsqlSpecIT.java | 11 +++++ .../esql/qa/multi_node/FieldExtractorIT.java | 9 ++++ .../xpack/esql/qa/single_node/EsqlSpecIT.java | 11 +++++ .../esql/qa/single_node/FieldExtractorIT.java | 9 ++++ .../xpack/esql/qa/single_node/RestEsqlIT.java | 22 ++++++++-- .../esql/qa/single_node/TSDBRestEsqlIT.java | 2 +- .../xpack/esql/qa/rest/EsqlSpecTestCase.java | 2 +- .../esql/qa/rest/FieldExtractorTestCase.java | 7 +++- .../esql/qa/rest/RestEnrichTestCase.java | 24 +++++++---- .../xpack/esql/qa/rest/RestEsqlTestCase.java | 41 ++++++++++--------- 15 files changed, 123 insertions(+), 35 deletions(-) diff --git a/x-pack/plugin/esql/qa/action/src/internalClusterTest/java/org/elasticsearch/test/esql/qa/action/CoreEsqlActionIT.java b/x-pack/plugin/esql/qa/action/src/internalClusterTest/java/org/elasticsearch/test/esql/qa/action/CoreEsqlActionIT.java index 8728b605134ac..6e172370f1389 100644 --- a/x-pack/plugin/esql/qa/action/src/internalClusterTest/java/org/elasticsearch/test/esql/qa/action/CoreEsqlActionIT.java +++ b/x-pack/plugin/esql/qa/action/src/internalClusterTest/java/org/elasticsearch/test/esql/qa/action/CoreEsqlActionIT.java @@ -18,6 +18,7 @@ import org.elasticsearch.xpack.core.esql.action.EsqlQueryRequest; import org.elasticsearch.xpack.core.esql.action.EsqlQueryRequestBuilder; import org.elasticsearch.xpack.core.esql.action.EsqlQueryResponse; +import org.elasticsearch.xpack.esql.version.EsqlVersion; import org.junit.Before; import java.util.ArrayList; @@ -127,7 +128,12 @@ public void testAccessAfterClose() { } } - protected EsqlQueryResponse run(EsqlQueryRequestBuilder request) { + protected EsqlQueryResponse run( + EsqlQueryRequestBuilder requestWithoutVersion + ) { + EsqlQueryRequestBuilder request = requestWithoutVersion.esqlVersion( + EsqlVersion.SNAPSHOT.toString() + ); try { // The variants here ensure API usage patterns if (randomBoolean()) { diff --git a/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlAsyncSecurityIT.java b/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlAsyncSecurityIT.java index 544eb82fb5ace..df88a99922894 100644 --- a/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlAsyncSecurityIT.java +++ b/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlAsyncSecurityIT.java @@ -90,6 +90,7 @@ private Response runAsync(String user, String command) throws IOException { } XContentBuilder json = JsonXContent.contentBuilder(); json.startObject(); + json.field("version", "snapshot"); json.field("query", command); addRandomPragmas(json); json.field("wait_for_completion_timeout", timeValueNanos(randomIntBetween(1, 1000))); diff --git a/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java b/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java index 7a9b90baa0d35..ccddf6d561407 100644 --- a/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java +++ b/x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java @@ -354,6 +354,7 @@ protected Response runESQLCommand(String user, String command) throws IOExceptio } XContentBuilder json = JsonXContent.contentBuilder(); json.startObject(); + json.field("version", "snapshot"); json.field("query", command); addRandomPragmas(json); json.endObject(); diff --git a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java index ca084ab26908d..02c6235a067af 100644 --- a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java +++ b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java @@ -22,6 +22,7 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.TestFeatureService; import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase; +import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase; import org.elasticsearch.xpack.ql.CsvSpecReader; import org.elasticsearch.xpack.ql.CsvSpecReader.CsvTestCase; import org.elasticsearch.xpack.ql.SpecReader; @@ -37,6 +38,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -231,4 +233,10 @@ static boolean hasIndexMetadata(String query) { } return false; } + + @Override + protected Map runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, List expectedWarnings) + throws IOException { + return super.runEsql(requestObject.esqlVersion("snapshot"), expectedWarnings); + } } diff --git a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java index 9a494f6309997..0b5b80f5af0d4 100644 --- a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java +++ b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java @@ -122,7 +122,7 @@ void indexDocs(RestClient client, String index, List docs) throws IOExcepti } private Map run(String query) throws IOException { - Map resp = runEsql(new RestEsqlTestCase.RequestObjectBuilder().query(query).build()); + Map resp = runEsql(new RestEsqlTestCase.RequestObjectBuilder().esqlVersion("snapshot").query(query).build()); logger.info("--> query {} response {}", query, resp); return resp; } diff --git a/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java b/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java index 67b916a815819..f8ada0d6cab06 100644 --- a/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java +++ b/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java @@ -9,9 +9,14 @@ import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase; +import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase; import org.elasticsearch.xpack.ql.CsvSpecReader.CsvTestCase; import org.junit.ClassRule; +import java.io.IOException; +import java.util.List; +import java.util.Map; + public class EsqlSpecIT extends EsqlSpecTestCase { @ClassRule public static ElasticsearchCluster cluster = Clusters.testCluster(); @@ -24,4 +29,10 @@ protected String getTestRestCluster() { public EsqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase, Mode mode) { super(fileName, groupName, testName, lineNumber, testCase, mode); } + + @Override + protected Map runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, List expectedWarnings) + throws IOException { + return super.runEsql(requestObject.esqlVersion("snapshot"), expectedWarnings); + } } diff --git a/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/FieldExtractorIT.java b/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/FieldExtractorIT.java index bcb83a31f7641..2a94a89fab688 100644 --- a/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/FieldExtractorIT.java +++ b/x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/FieldExtractorIT.java @@ -12,8 +12,12 @@ import org.elasticsearch.test.TestClustersThreadFilter; import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.esql.qa.rest.FieldExtractorTestCase; +import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase; import org.junit.ClassRule; +import java.io.IOException; +import java.util.Map; + @ThreadLeakFilters(filters = TestClustersThreadFilter.class) public class FieldExtractorIT extends FieldExtractorTestCase { @ClassRule @@ -23,4 +27,9 @@ public class FieldExtractorIT extends FieldExtractorTestCase { protected String getTestRestCluster() { return cluster.getHttpAddresses(); } + + @Override + protected Map runEsqlSync(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException { + return super.runEsqlSync(requestObject.esqlVersion("snapshot")); + } } diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java index db737e3678752..5e47c9ef7ada3 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java +++ b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java @@ -12,9 +12,14 @@ import org.elasticsearch.test.TestClustersThreadFilter; import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase; +import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase; import org.elasticsearch.xpack.ql.CsvSpecReader.CsvTestCase; import org.junit.ClassRule; +import java.io.IOException; +import java.util.List; +import java.util.Map; + @ThreadLeakFilters(filters = TestClustersThreadFilter.class) public class EsqlSpecIT extends EsqlSpecTestCase { @ClassRule @@ -28,4 +33,10 @@ protected String getTestRestCluster() { public EsqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase, Mode mode) { super(fileName, groupName, testName, lineNumber, testCase, mode); } + + @Override + protected Map runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, List expectedWarnings) + throws IOException { + return super.runEsql(requestObject.esqlVersion("snapshot"), expectedWarnings); + } } diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/FieldExtractorIT.java b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/FieldExtractorIT.java index 695db7ddf4c3d..e2d7f96db8e43 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/FieldExtractorIT.java +++ b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/FieldExtractorIT.java @@ -12,8 +12,12 @@ import org.elasticsearch.test.TestClustersThreadFilter; import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.esql.qa.rest.FieldExtractorTestCase; +import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase; import org.junit.ClassRule; +import java.io.IOException; +import java.util.Map; + @ThreadLeakFilters(filters = TestClustersThreadFilter.class) public class FieldExtractorIT extends FieldExtractorTestCase { @ClassRule @@ -23,4 +27,9 @@ public class FieldExtractorIT extends FieldExtractorTestCase { protected String getTestRestCluster() { return cluster.getHttpAddresses(); } + + @Override + protected Map runEsqlSync(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException { + return super.runEsqlSync(requestObject.esqlVersion("snapshot")); + } } diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java index 6743657e86874..89a6bda8d10a2 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java +++ b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java @@ -91,7 +91,7 @@ public void testInvalidPragma() throws IOException { } RequestObjectBuilder builder = new RequestObjectBuilder().query("from test-index | limit 1 | keep f"); builder.pragmas(Settings.builder().put("data_partitioning", "invalid-option").build()); - ResponseException re = expectThrows(ResponseException.class, () -> runEsqlSync(builder)); + ResponseException re = expectThrows(ResponseException.class, () -> runEsql(builder, List.of(), Mode.SYNC)); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("No enum constant")); assertThat(deleteIndex("test-index").isAcknowledged(), is(true)); // clean up @@ -101,7 +101,7 @@ public void testPragmaNotAllowed() throws IOException { assumeFalse("pragma only disabled on release builds", Build.current().isSnapshot()); RequestObjectBuilder builder = new RequestObjectBuilder().query("row a = 1, b = 2"); builder.pragmas(Settings.builder().put("data_partitioning", "shard").build()); - ResponseException re = expectThrows(ResponseException.class, () -> runEsqlSync(builder)); + ResponseException re = expectThrows(ResponseException.class, () -> runEsql(builder, List.of(), Mode.SYNC)); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("[pragma] only allowed in snapshot builds")); } @@ -197,10 +197,26 @@ public void testIncompatibleMappingsErrors() throws IOException { } private void assertException(String query, String... errorMessages) throws IOException { - ResponseException re = expectThrows(ResponseException.class, () -> runEsqlSync(new RequestObjectBuilder().query(query))); + ResponseException re = expectThrows( + ResponseException.class, + () -> runEsql(new RequestObjectBuilder().query(query), List.of(), Mode.SYNC) + ); assertThat(re.getResponse().getStatusLine().getStatusCode(), equalTo(400)); for (var error : errorMessages) { assertThat(re.getMessage(), containsString(error)); } } + + @Override + protected Map runEsql(RequestObjectBuilder requestObject, List expectedWarnings, Mode mode) throws IOException { + if (requestObject.esqlVersion() == null) { + requestObject.esqlVersion("snapshot"); + } + return super.runEsql(requestObject, expectedWarnings, mode); + } + + @Override + protected RequestObjectBuilder builder() throws IOException { + return super.builder().esqlVersion("snapshot"); + } } diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/TSDBRestEsqlIT.java b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/TSDBRestEsqlIT.java index b7ab7b623d460..6c18bfd69cd9b 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/TSDBRestEsqlIT.java +++ b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/TSDBRestEsqlIT.java @@ -63,7 +63,7 @@ public void testTimeSeriesQuerying() throws IOException { RestEsqlTestCase.RequestObjectBuilder builder = new RestEsqlTestCase.RequestObjectBuilder().query( "FROM k8s | KEEP k8s.pod.name, @timestamp" - ); + ).esqlVersion("snapshot"); builder.pragmas(Settings.builder().put("time_series", true).build()); Map result = runEsqlSync(builder); @SuppressWarnings("unchecked") diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java index 349954450904d..99dd2e5aa1182 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java @@ -160,7 +160,7 @@ protected final void doTest() throws Throwable { assertResults(expectedColumnsWithValues, actualColumns, actualValues, testCase.ignoreOrder, logger); } - private Map runEsql(RequestObjectBuilder requestObject, List expectedWarnings) throws IOException { + protected Map runEsql(RequestObjectBuilder requestObject, List expectedWarnings) throws IOException { if (mode == Mode.ASYNC) { assert supportsAsync(); return RestEsqlTestCase.runEsqlAsync(requestObject, expectedWarnings); diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java index d107f8a147fd6..b5d28159fed1e 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java @@ -45,7 +45,6 @@ import static org.elasticsearch.test.MapMatcher.assertMap; import static org.elasticsearch.test.MapMatcher.matchesMap; import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.entityToMap; -import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.runEsqlSync; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.containsString; @@ -1189,7 +1188,7 @@ private static String randomPrerelease() { private record StoreAndDocValues(Boolean store, Boolean docValues) {} - private static class Test { + private class Test { private final String type; private final Map subFields = new TreeMap<>(); @@ -1417,6 +1416,10 @@ private Map fetchAll() throws IOException { } } + protected Map runEsqlSync(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException { + return RestEsqlTestCase.runEsqlSync(requestObject); + } + private static Map columnInfo(String name, String type) { return Map.of("name", name, "type", type); } diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEnrichTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEnrichTestCase.java index 752775b20b0e3..498705cb6083e 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEnrichTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEnrichTestCase.java @@ -144,7 +144,7 @@ public void wipeTestData() throws IOException { public void testNonExistentEnrichPolicy() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> RestEsqlTestCase.runEsqlSync(new RestEsqlTestCase.RequestObjectBuilder().query("from test | enrich countris"), List.of()) + () -> runEsql(new RestEsqlTestCase.RequestObjectBuilder().query("from test | enrich countris"), Mode.SYNC) ); assertThat( EntityUtils.toString(re.getResponse().getEntity()), @@ -155,9 +155,7 @@ public void testNonExistentEnrichPolicy() throws IOException { public void testNonExistentEnrichPolicy_KeepField() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> RestEsqlTestCase.runEsqlSync( - new RestEsqlTestCase.RequestObjectBuilder().query("from test | enrich countris | keep number") - ) + () -> runEsql(new RestEsqlTestCase.RequestObjectBuilder().query("from test | enrich countris | keep number"), Mode.SYNC) ); assertThat( EntityUtils.toString(re.getResponse().getEntity()), @@ -178,7 +176,6 @@ public void testMatchField_ImplicitFieldsList() throws IOException { public void testMatchField_ImplicitFieldsList_WithStats() throws IOException { Map result = runEsql( new RestEsqlTestCase.RequestObjectBuilder().query("from test | enrich countries | stats s = sum(number) by country_name") - ); var columns = List.of(Map.of("name", "s", "type", "long"), Map.of("name", "country_name", "type", "keyword")); var values = List.of(List.of(2000, "United States of America"), List.of(5000, "China")); @@ -187,10 +184,23 @@ public void testMatchField_ImplicitFieldsList_WithStats() throws IOException { } private Map runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException { + return runEsql(requestObject, this.mode, NO_WARNINGS); + } + + private static Map runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, Mode mode) throws IOException { + return runEsql(requestObject, mode, NO_WARNINGS); + } + + private static Map runEsql( + RestEsqlTestCase.RequestObjectBuilder requestObject, + Mode mode, + List expectedWarnings + ) throws IOException { + requestObject = requestObject.esqlVersion("snapshot"); if (mode == Mode.ASYNC) { - return RestEsqlTestCase.runEsqlAsync(requestObject, NO_WARNINGS); + return RestEsqlTestCase.runEsqlAsync(requestObject, expectedWarnings); } else { - return RestEsqlTestCase.runEsqlSync(requestObject, NO_WARNINGS); + return RestEsqlTestCase.runEsqlSync(requestObject, expectedWarnings); } } diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java index 301b30df5647a..55e0b0f326e72 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java @@ -119,6 +119,7 @@ public static class RequestObjectBuilder { private boolean isBuilt = false; private Boolean keepOnCompletion = null; + private String esqlVersion = null; public RequestObjectBuilder() throws IOException { this(randomFrom(XContentType.values())); @@ -129,6 +130,12 @@ public RequestObjectBuilder(XContentType type) throws IOException { builder.startObject(); } + public RequestObjectBuilder esqlVersion(String esqlVersion) throws IOException { + this.esqlVersion = esqlVersion; + builder.field("version", esqlVersion); + return this; + } + public RequestObjectBuilder query(String query) throws IOException { builder.field("query", query); return this; @@ -160,6 +167,10 @@ public RequestObjectBuilder keepOnCompletion(boolean value) throws IOException { return this; } + public String esqlVersion() { + return esqlVersion; + } + Boolean keepOnCompletion() { return keepOnCompletion; } @@ -482,7 +493,7 @@ public void testWarningHeadersOnFailedConversions() throws IOException { Request request = prepareRequest(SYNC); var query = fromIndex() + " | eval asInt = to_int(case(integer % 2 == 0, to_str(integer), keyword)) | limit 1000"; - var mediaType = attachBody(new RequestObjectBuilder().query(query).build(), request); + var mediaType = attachBody(builder().query(query).build(), request); RequestOptions.Builder options = request.getOptions().toBuilder(); options.setWarningsHandler(WarningsHandler.PERMISSIVE); @@ -522,7 +533,7 @@ public void testMetadataFieldsOnMultipleIndices() throws IOException { assertEquals(201, client().performRequest(request).getStatusLine().getStatusCode()); var query = fromIndex() + "* metadata _index, _version, _id | sort _version"; - Map result = runEsql(new RequestObjectBuilder().query(query)); + Map result = runEsql(builder().query(query)); var columns = List.of( Map.of("name", "a", "type", "long"), Map.of("name", "_index", "type", "keyword"), @@ -538,25 +549,19 @@ public void testMetadataFieldsOnMultipleIndices() throws IOException { } public void testErrorMessageForEmptyParams() throws IOException { - ResponseException re = expectThrows( - ResponseException.class, - () -> runEsql(new RequestObjectBuilder().query("row a = 1 | eval x = ?").params("[]")) - ); + ResponseException re = expectThrows(ResponseException.class, () -> runEsql(builder().query("row a = 1 | eval x = ?").params("[]"))); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("Not enough actual parameters 0")); } public void testErrorMessageForInvalidParams() throws IOException { - ResponseException re = expectThrows( - ResponseException.class, - () -> runEsql(new RequestObjectBuilder().query("row a = 1").params("[{\"x\":\"y\"}]")) - ); + ResponseException re = expectThrows(ResponseException.class, () -> runEsql(builder().query("row a = 1").params("[{\"x\":\"y\"}]"))); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("Required [value, type]")); } public void testErrorMessageForMissingTypeInParams() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> runEsql(new RequestObjectBuilder().query("row a = 1").params("[\"x\", 123, true, {\"value\": \"y\"}]")) + () -> runEsql(builder().query("row a = 1").params("[\"x\", 123, true, {\"value\": \"y\"}]")) ); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("Required [type]")); } @@ -564,7 +569,7 @@ public void testErrorMessageForMissingTypeInParams() throws IOException { public void testErrorMessageForMissingValueInParams() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> runEsql(new RequestObjectBuilder().query("row a = 1").params("[\"x\", 123, true, {\"type\": \"y\"}]")) + () -> runEsql(builder().query("row a = 1").params("[\"x\", 123, true, {\"type\": \"y\"}]")) ); assertThat(EntityUtils.toString(re.getResponse().getEntity()), containsString("Required [value]")); } @@ -572,7 +577,7 @@ public void testErrorMessageForMissingValueInParams() throws IOException { public void testErrorMessageForInvalidTypeInParams() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> runEsqlSync(new RequestObjectBuilder().query("row a = 1 | eval x = ?").params("[{\"type\": \"byte\", \"value\": 5}]")) + () -> runEsqlSync(builder().query("row a = 1 | eval x = ?").params("[{\"type\": \"byte\", \"value\": 5}]")) ); assertThat( EntityUtils.toString(re.getResponse().getEntity()), @@ -609,7 +614,7 @@ public void testErrorMessageForLiteralDateMathOverflowOnNegation() throws IOExce private void assertExceptionForDateMath(String dateMathString, String errorSubstring) throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> runEsql(new RequestObjectBuilder().query("row a = 1 | eval x = now() + (" + dateMathString + ")")) + () -> runEsql(builder().query("row a = 1 | eval x = now() + (" + dateMathString + ")")) ); String responseMessage = EntityUtils.toString(re.getResponse().getEntity()); @@ -622,9 +627,7 @@ private void assertExceptionForDateMath(String dateMathString, String errorSubst public void testErrorMessageForArrayValuesInParams() throws IOException { ResponseException re = expectThrows( ResponseException.class, - () -> runEsql( - new RequestObjectBuilder().query("row a = 1 | eval x = ?").params("[{\"type\": \"integer\", \"value\": [5, 6, 7]}]") - ) + () -> runEsql(builder().query("row a = 1 | eval x = ?").params("[{\"type\": \"integer\", \"value\": [5, 6, 7]}]")) ); assertThat( EntityUtils.toString(re.getResponse().getEntity()), @@ -670,7 +673,7 @@ public static Map runEsqlSync(RequestObjectBuilder requestObject return runEsqlSync(requestObject, NO_WARNINGS); } - static Map runEsql(RequestObjectBuilder requestObject, List expectedWarnings, Mode mode) throws IOException { + protected Map runEsql(RequestObjectBuilder requestObject, List expectedWarnings, Mode mode) throws IOException { if (mode == ASYNC) { return runEsqlAsync(requestObject, expectedWarnings); } else { @@ -988,7 +991,7 @@ private static String repeatValueAsMV(Object value) { return "[" + value + ", " + value + "]"; } - private static RequestObjectBuilder builder() throws IOException { + protected RequestObjectBuilder builder() throws IOException { return new RequestObjectBuilder(); }