From f95c2a85cfec136ace08d394c20fcde8be18ca37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Fri, 17 Oct 2025 12:51:54 +0200 Subject: [PATCH 1/5] Add capability and YAML tests for request and SET time_zone parameters --- .../xpack/esql/action/EsqlCapabilities.java | 5 + .../rest-api-spec/test/esql/240_timezone.yml | 188 ++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_timezone.yml diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index df06a1109ecc9..b37d1d827997d 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -1516,6 +1516,11 @@ public enum Cap { */ FIX_FILTER_ORDINALS, + /** + * "time_zone" parameter in request body and in {@code SET "time_zone"="x"} + */ + GLOBAL_TIMEZONE_PARAMETER(Build.current().isSnapshot()), + ; private final boolean enabled; diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_timezone.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_timezone.yml new file mode 100644 index 0000000000000..c877a65effa19 --- /dev/null +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_timezone.yml @@ -0,0 +1,188 @@ +--- +setup: + - requires: + capabilities: + - method: POST + path: /_query + parameters: [ ] + capabilities: [ global_timezone_parameter ] + test_runner_features: [ capabilities ] + reason: "Check timezone capability" + - do: + indices.create: + index: logs + body: + mappings: + properties: + "@timestamp": + type: date + + - do: + bulk: + index: tzs + refresh: true + body: + - { "index": { } } + - { "@timestamp": "2025-05-31T00:00:00Z" } + - { "index": { } } + - { "@timestamp": "2025-05-31T01:00:00Z" } + - { "index": { } } + - { "@timestamp": "2025-05-31T22:00:00Z" } + - { "index": { } } + - { "@timestamp": "2025-05-31T23:00:00Z" } + +--- +Default UTC: + - do: + esql.query: + body: + query: | + FROM tzs + | EVAL + hour=DATE_EXTRACT("hour_of_day", @timestamp), + day_name=DAY_NAME(@timestamp), + month_name=MONTH_NAME(@timestamp) + | SORT @timestamp ASC + | LIMIT 5 + + - length: { columns: 4 } + - match: { columns.0.name: "@timestamp" } + - match: { columns.1.name: "hour" } + - match: { columns.2.name: "day_name" } + - match: { columns.3.name: "month_name" } + + - length: { values: 4 } + - match: { values.0.0: "2025-05-31T00:00:00.000Z" } + - match: { values.0.1: 0 } + - match: { values.0.2: "Saturday" } + - match: { values.0.3: "May" } + - match: { values.1.0: "2025-05-31T01:00:00.000Z" } + - match: { values.1.1: 1 } + - match: { values.1.2: "Saturday" } + - match: { values.1.3: "May" } + - match: { values.2.0: "2025-05-31T22:00:00.000Z" } + - match: { values.2.1: 22 } + - match: { values.2.2: "Saturday" } + - match: { values.2.3: "May" } + - match: { values.3.0: "2025-05-31T23:00:00.000Z" } + - match: { values.3.1: 23 } + - match: { values.3.2: "Saturday" } + - match: { values.3.3: "May" } + +--- +Paris tz with SET: + - do: + esql.query: + body: + query: | + SET time_zone="Europe/Paris"; + FROM tzs + | EVAL + hour=DATE_EXTRACT("hour_of_day", @timestamp), + day_name=DAY_NAME(@timestamp), + month_name=MONTH_NAME(@timestamp) + | SORT @timestamp ASC + | LIMIT 5 + + - length: { columns: 4 } + - match: { columns.0.name: "@timestamp" } + - match: { columns.1.name: "hour" } + - match: { columns.2.name: "day_name" } + - match: { columns.3.name: "month_name" } + + - length: { values: 4 } + - match: { values.0.0: "2025-05-31T00:00:00.000Z" } + - match: { values.0.1: 2 } + - match: { values.0.2: "Saturday" } + - match: { values.0.3: "May" } + - match: { values.1.0: "2025-05-31T01:00:00.000Z" } + - match: { values.1.1: 3 } + - match: { values.1.2: "Saturday" } + - match: { values.1.3: "May" } + - match: { values.2.0: "2025-05-31T22:00:00.000Z" } + - match: { values.2.1: 0 } + - match: { values.2.2: "Sunday" } + - match: { values.2.3: "June" } + - match: { values.3.0: "2025-05-31T23:00:00.000Z" } + - match: { values.3.1: 1 } + - match: { values.3.2: "Sunday" } + - match: { values.3.3: "June" } + +--- +Paris tz with request parameter: + - do: + esql.query: + body: + time_zone: "Europe/Paris" + query: | + FROM tzs + | EVAL + hour=DATE_EXTRACT("hour_of_day", @timestamp), + day_name=DAY_NAME(@timestamp), + month_name=MONTH_NAME(@timestamp) + | SORT @timestamp ASC + | LIMIT 5 + + - length: { columns: 4 } + - match: { columns.0.name: "@timestamp" } + - match: { columns.1.name: "hour" } + - match: { columns.2.name: "day_name" } + - match: { columns.3.name: "month_name" } + + - length: { values: 4 } + - match: { values.0.0: "2025-05-31T00:00:00.000Z" } + - match: { values.0.1: 2 } + - match: { values.0.2: "Saturday" } + - match: { values.0.3: "May" } + - match: { values.1.0: "2025-05-31T01:00:00.000Z" } + - match: { values.1.1: 3 } + - match: { values.1.2: "Saturday" } + - match: { values.1.3: "May" } + - match: { values.2.0: "2025-05-31T22:00:00.000Z" } + - match: { values.2.1: 0 } + - match: { values.2.2: "Sunday" } + - match: { values.2.3: "June" } + - match: { values.3.0: "2025-05-31T23:00:00.000Z" } + - match: { values.3.1: 1 } + - match: { values.3.2: "Sunday" } + - match: { values.3.3: "June" } + +--- +Set overrides request parameter: + - do: + esql.query: + body: + time_zone: "Europe/Paris" + query: | + SET time_zone="+04:00"; + FROM tzs + | EVAL + hour=DATE_EXTRACT("hour_of_day", @timestamp), + day_name=DAY_NAME(@timestamp), + month_name=MONTH_NAME(@timestamp) + | SORT @timestamp ASC + | LIMIT 5 + + - length: { columns: 4 } + - match: { columns.0.name: "@timestamp" } + - match: { columns.1.name: "hour" } + - match: { columns.2.name: "day_name" } + - match: { columns.3.name: "month_name" } + + - length: { values: 4 } + - match: { values.0.0: "2025-05-31T00:00:00.000Z" } + - match: { values.0.1: 4 } + - match: { values.0.2: "Saturday" } + - match: { values.0.3: "May" } + - match: { values.1.0: "2025-05-31T01:00:00.000Z" } + - match: { values.1.1: 5 } + - match: { values.1.2: "Saturday" } + - match: { values.1.3: "May" } + - match: { values.2.0: "2025-05-31T22:00:00.000Z" } + - match: { values.2.1: 2 } + - match: { values.2.2: "Sunday" } + - match: { values.2.3: "June" } + - match: { values.3.0: "2025-05-31T23:00:00.000Z" } + - match: { values.3.1: 3 } + - match: { values.3.2: "Sunday" } + - match: { values.3.3: "June" } From 569d9e53081655dbb9627107105ef62e6fdd0967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Fri, 17 Oct 2025 14:44:58 +0200 Subject: [PATCH 2/5] Add SET CSV tests, and adapted CsvTests to work with SET statements --- .../xpack/esql/CsvSpecReader.java | 14 +------- .../xpack/esql/EsqlTestUtils.java | 11 ++++-- .../src/main/resources/set.csv-spec | 36 +++++++++++++++++++ .../xpack/esql/parser/EsqlParser.java | 5 +++ .../xpack/esql/session/Configuration.java | 2 +- .../elasticsearch/xpack/esql/CsvTests.java | 23 ++++++++---- 6 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java index ba0d11059a69b..0f315b0d12541 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java @@ -13,9 +13,6 @@ import java.util.function.Function; import java.util.regex.Pattern; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - public final class CsvSpecReader { private CsvSpecReader() {} @@ -25,9 +22,6 @@ public static SpecReader.Parser specParser() { } public static class CsvSpecParser implements SpecReader.Parser { - private static final String SCHEMA_PREFIX = "schema::"; - - private final StringBuilder earlySchema = new StringBuilder(); private final StringBuilder query = new StringBuilder(); private final StringBuilder data = new StringBuilder(); private final List requiredCapabilities = new ArrayList<>(); @@ -39,10 +33,7 @@ private CsvSpecParser() {} public Object parse(String line) { // read the query if (testCase == null) { - if (line.startsWith(SCHEMA_PREFIX)) { - assertThat("Early schema already declared " + earlySchema, earlySchema.length(), is(0)); - earlySchema.append(line.substring(SCHEMA_PREFIX.length()).trim()); - } else if (line.toLowerCase(Locale.ROOT).startsWith("required_capability:")) { + if (line.toLowerCase(Locale.ROOT).startsWith("required_capability:")) { requiredCapabilities.add(line.substring("required_capability:".length()).trim()); } else { if (line.endsWith(";")) { @@ -50,10 +41,8 @@ public Object parse(String line) { testCase = new CsvTestCase(); query.append(line.substring(0, line.length() - 1).trim()); testCase.query = query.toString(); - testCase.earlySchema = earlySchema.toString(); testCase.requiredCapabilities = List.copyOf(requiredCapabilities); requiredCapabilities.clear(); - earlySchema.setLength(0); query.setLength(0); } // keep reading the query @@ -109,7 +98,6 @@ private static Pattern warningRegexToPattern(String regex) { public static class CsvTestCase { public String query; - public String earlySchema; public String expectedResults; private final List expectedWarnings = new ArrayList<>(); private final List expectedWarningsRegexString = new ArrayList<>(); diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java index 88469a8d19e8c..ee57a69ae021b 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java @@ -78,7 +78,6 @@ import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.core.type.DataType; import org.elasticsearch.xpack.esql.core.type.EsField; -import org.elasticsearch.xpack.esql.core.util.DateUtils; import org.elasticsearch.xpack.esql.core.util.StringUtils; import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry; import org.elasticsearch.xpack.esql.expression.function.scalar.spatial.StGeohash; @@ -99,6 +98,8 @@ import org.elasticsearch.xpack.esql.inference.InferenceService; import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext; import org.elasticsearch.xpack.esql.parser.QueryParam; +import org.elasticsearch.xpack.esql.plan.EsqlStatement; +import org.elasticsearch.xpack.esql.plan.QuerySettings; import org.elasticsearch.xpack.esql.plan.logical.Enrich; import org.elasticsearch.xpack.esql.plan.logical.EsRelation; import org.elasticsearch.xpack.esql.plan.logical.Limit; @@ -516,9 +517,9 @@ private static ThreadPool createMockThreadPool() { private EsqlTestUtils() {} - public static Configuration configuration(QueryPragmas pragmas, String query) { + public static Configuration configuration(QueryPragmas pragmas, String query, EsqlStatement statement) { return new Configuration( - DateUtils.UTC, + statement.setting(QuerySettings.TIME_ZONE), Locale.US, null, null, @@ -535,6 +536,10 @@ public static Configuration configuration(QueryPragmas pragmas, String query) { ); } + public static Configuration configuration(QueryPragmas pragmas, String query) { + return configuration(pragmas, query, new EsqlStatement(null, List.of())); + } + public static Configuration configuration(QueryPragmas pragmas) { return configuration(pragmas, StringUtils.EMPTY); } diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec new file mode 100644 index 0000000000000..f1336ac6ff797 --- /dev/null +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec @@ -0,0 +1,36 @@ +set +required_capability: global_timezone_parameter + +set time_zone="+02:00"; from employees +| sort emp_no +| keep emp_no, hire_date +| eval hour = date_extract("hour_of_day", hire_date) +| limit 1; + +emp_no:integer | hire_date:date | hour:long +10001 | 1986-06-26T00:00:00.000Z | 2 +; + +set with foldable +required_capability: global_timezone_parameter + +set time_zone="+02:00"; ROW date = "1986-06-26T00:00:00.000Z"::date +| eval hour = date_extract("hour_of_day", date) +; + +date:date | hour:long +1986-06-26T00:00:00.000Z | 2 +; + +last set prevails +required_capability: global_timezone_parameter + +set time_zone="+02:00"; set time_zone="+05:00"; from employees +| sort emp_no +| keep emp_no, hire_date +| eval hour = date_extract("hour_of_day", hire_date) +| limit 1; + +emp_no:integer | hire_date:date | hour:long +10001 | 1986-06-26T00:00:00.000Z | 5 +; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java index 1c844d3c15f6c..0c0a6a18c9d11 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java @@ -115,6 +115,11 @@ public LogicalPlan createStatement(String query, QueryParams params, PlanTelemet return invokeParser(query, params, metrics, EsqlBaseParser::singleStatement, AstBuilder::plan); } + // testing utility + public EsqlStatement createQuery(String query) { + return createQuery(query, new QueryParams()); + } + // testing utility public EsqlStatement createQuery(String query, QueryParams params) { return createQuery(query, params, new PlanTelemetry(new EsqlFunctionRegistry())); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/Configuration.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/Configuration.java index 7e2dea975f326..9d248ffc19abe 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/Configuration.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/Configuration.java @@ -202,7 +202,7 @@ public long absoluteStartedTimeInMillis() { /** * @return Start time of the ESQL query in nanos */ - public long getQueryStartTimeNanos() { + public long queryStartTimeNanos() { return queryStartTimeNanos; } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java index f90547f57c0ff..99eefe0ba886d 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java @@ -79,6 +79,7 @@ import org.elasticsearch.xpack.esql.optimizer.LogicalPreOptimizerContext; import org.elasticsearch.xpack.esql.optimizer.TestLocalPhysicalPlanOptimizer; import org.elasticsearch.xpack.esql.parser.EsqlParser; +import org.elasticsearch.xpack.esql.plan.EsqlStatement; import org.elasticsearch.xpack.esql.plan.logical.Enrich; import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; import org.elasticsearch.xpack.esql.plan.physical.ChangePointExec; @@ -189,9 +190,13 @@ public class CsvTests extends ESTestCase { private final CsvSpecReader.CsvTestCase testCase; private final String instructions; - private final Configuration configuration = EsqlTestUtils.configuration( - new QueryPragmas(Settings.builder().put("page_size", randomPageSize()).build()) - ); + /** + * The configuration to be used in the tests. + *

+ * Initialized in {@link #executePlan}. + *

+ */ + private Configuration configuration; private final EsqlFunctionRegistry functionRegistry = new EsqlFunctionRegistry(); private final EsqlParser parser = new EsqlParser(); private final Mapper mapper = new Mapper(); @@ -526,6 +531,7 @@ private static EnrichPolicy loadEnrichPolicyMapping(String policyFileName) { private LogicalPlan analyzedPlan( LogicalPlan parsed, + Configuration configuration, CsvTestsDataLoader.MultiIndexTestDataset datasets, TransportVersion minimumVersion ) { @@ -594,11 +600,16 @@ private static TestPhysicalOperationProviders testOperationProviders( } private ActualResults executePlan(BigArrays bigArrays) throws Exception { - LogicalPlan parsed = parser.createStatement(testCase.query); - var testDatasets = testDatasets(parsed); + EsqlStatement statement = parser.createQuery(testCase.query); + this.configuration = EsqlTestUtils.configuration( + new QueryPragmas(Settings.builder().put("page_size", randomPageSize()).build()), + testCase.query, + statement + ); + var testDatasets = testDatasets(statement.plan()); // Specifically use the newest transport version; the csv tests correspond to a single node cluster on the current version. TransportVersion minimumVersion = TransportVersion.current(); - LogicalPlan analyzed = analyzedPlan(parsed, testDatasets, minimumVersion); + LogicalPlan analyzed = analyzedPlan(statement.plan(), configuration, testDatasets, minimumVersion); FoldContext foldCtx = FoldContext.small(); EsqlSession session = new EsqlSession( From cc15c9fa9590e5cff11a6bb903b300dee71c6c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Fri, 17 Oct 2025 14:52:55 +0200 Subject: [PATCH 3/5] Escape ; in csv tests with backslash --- .../org/elasticsearch/xpack/esql/CsvSpecReader.java | 8 +++++++- .../qa/testFixtures/src/main/resources/set.csv-spec | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java index 0f315b0d12541..0af1ac662fa69 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvSpecReader.java @@ -36,7 +36,13 @@ public Object parse(String line) { if (line.toLowerCase(Locale.ROOT).startsWith("required_capability:")) { requiredCapabilities.add(line.substring("required_capability:".length()).trim()); } else { - if (line.endsWith(";")) { + if (line.endsWith("\\;")) { + // SET statement with escaped ";" + var updatedLine = line.substring(0, line.length() - 2); + query.append(updatedLine); + query.append(";"); + query.append("\r\n"); + } else if (line.endsWith(";")) { // pick up the query testCase = new CsvTestCase(); query.append(line.substring(0, line.length() - 1).trim()); diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec index f1336ac6ff797..24702a83ce79f 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/set.csv-spec @@ -1,7 +1,8 @@ set required_capability: global_timezone_parameter -set time_zone="+02:00"; from employees +set time_zone="+02:00"\; +from employees | sort emp_no | keep emp_no, hire_date | eval hour = date_extract("hour_of_day", hire_date) @@ -14,7 +15,8 @@ emp_no:integer | hire_date:date | hour:long set with foldable required_capability: global_timezone_parameter -set time_zone="+02:00"; ROW date = "1986-06-26T00:00:00.000Z"::date +set time_zone="+02:00"\; +ROW date = "1986-06-26T00:00:00.000Z"::date | eval hour = date_extract("hour_of_day", date) ; @@ -25,7 +27,9 @@ date:date | hour:long last set prevails required_capability: global_timezone_parameter -set time_zone="+02:00"; set time_zone="+05:00"; from employees +set time_zone="+02:00"\; +set time_zone="+05:00"\; +from employees | sort emp_no | keep emp_no, hire_date | eval hour = date_extract("hour_of_day", hire_date) From 449abe68e457f6f7b9d096fba088038d257b8353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Cea=20Fontenla?= Date: Fri, 17 Oct 2025 18:12:51 +0200 Subject: [PATCH 4/5] Randomize configuration in function tests, and make it static for the ones that use it --- .../xpack/esql/EsqlTestUtils.java | 2 +- .../function/AbstractAggregationTestCase.java | 2 + .../function/AbstractFunctionTestCase.java | 4 ++ .../expression/function/TestCaseSupplier.java | 55 ++++++++++++++++++- ...AbstractConfigurationFunctionTestCase.java | 29 ++-------- .../scalar/date/DateExtractTests.java | 9 +-- .../function/scalar/date/DateFormatTests.java | 9 +++ .../function/scalar/date/DayNameTests.java | 7 ++- .../function/scalar/date/MonthNameTests.java | 6 +- .../function/scalar/date/NowTests.java | 2 +- .../function/scalar/string/ToLowerTests.java | 4 +- .../function/scalar/string/ToUpperTests.java | 4 +- 12 files changed, 90 insertions(+), 43 deletions(-) diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java index ee57a69ae021b..9837c7232c1ab 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java @@ -545,7 +545,7 @@ public static Configuration configuration(QueryPragmas pragmas) { } public static Configuration configuration(String query) { - return configuration(new QueryPragmas(Settings.EMPTY), query); + return configuration(QueryPragmas.EMPTY, query); } public static AnalyzerSettings queryClusterSettings() { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java index 69b6ff4ff30d1..7805a8e603334 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java @@ -117,6 +117,8 @@ protected static List withNoRowsExpectingNull(List td.isMultiRow() ? td.withData(List.of()) : td).toList(); return new TestCaseSupplier.TestCase( + testCase.getSource(), + testCase.getConfiguration(), newData, testCase.evaluatorToString(), testCase.expectedType(), diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java index 61de9ce7601f9..8a60cbf756e3d 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java @@ -179,6 +179,8 @@ protected static List anyNullIsNull( }).toList(); TestCaseSupplier.TypedData nulledData = oc.getData().get(finalNullPosition); return new TestCaseSupplier.TestCase( + oc.getSource(), + oc.getConfiguration(), data, evaluatorToString.evaluatorToString(finalNullPosition, nulledData, oc.evaluatorToString()), expectedType.expectedType(finalNullPosition, nulledData.type(), oc), @@ -211,6 +213,8 @@ protected static List anyNullIsNull( ) .toList(); return new TestCaseSupplier.TestCase( + oc.getSource(), + oc.getConfiguration(), data, equalTo("LiteralsEvaluator[lit=null]"), expectedType.expectedType(finalNullPosition, DataType.NULL, oc), diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java index 3d75db67e7604..e00a701ffe463 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java @@ -23,6 +23,7 @@ import org.elasticsearch.logging.Logger; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.esql.ConfigurationTestUtils; import org.elasticsearch.xpack.esql.EsqlTestUtils; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.expression.Literal; @@ -42,8 +43,10 @@ import java.time.Period; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.BinaryOperator; import java.util.function.DoubleFunction; @@ -1570,6 +1573,17 @@ public static String castToDoubleEvaluator(String original, DataType current) { throw new UnsupportedOperationException(); } + public static List mapTestCases( + Collection suppliers, + Function mapper + ) { + return suppliers.stream().map(supplier -> + new TestCaseSupplier(supplier.name(), supplier.types(), () -> + mapper.apply(supplier.get()) + ) + ).toList(); + } + public static final class TestCase { /** * The {@link Source} this test case should be run with @@ -1655,6 +1669,8 @@ public static TestCase typeError(List data, String expectedTypeError) Object extra ) { this( + TEST_SOURCE, + ConfigurationTestUtils.randomConfiguration(TEST_SOURCE.text(), Map.of()), data, evaluatorToString, expectedType, @@ -1670,6 +1686,8 @@ public static TestCase typeError(List data, String expectedTypeError) } TestCase( + Source source, + Configuration configuration, List data, Matcher evaluatorToString, DataType expectedType, @@ -1682,8 +1700,8 @@ public static TestCase typeError(List data, String expectedTypeError) Object extra, boolean canBuildEvaluator ) { - this.source = TEST_SOURCE; - this.configuration = TEST_CONFIGURATION; + this.source = source; + this.configuration = configuration; this.data = data; this.evaluatorToString = evaluatorToString; this.expectedType = expectedType == null ? null : expectedType.noText(); @@ -1779,11 +1797,34 @@ public Object extra() { return extra; } + /** + * Build a new {@link TestCase} with new {@link #configuration}. + */ + public TestCase withConfiguration(Configuration configuration) { + return new TestCase( + source, + configuration, + data, + evaluatorToString, + expectedType, + matcher, + expectedWarnings, + expectedBuildEvaluatorWarnings, + expectedTypeError, + foldingExceptionClass, + foldingExceptionMessage, + extra, + canBuildEvaluator + ); + } + /** * Build a new {@link TestCase} with new {@link #data}. */ public TestCase withData(List data) { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, @@ -1803,6 +1844,8 @@ public TestCase withData(List data) { */ public TestCase withExtra(Object extra) { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, @@ -1819,6 +1862,8 @@ public TestCase withExtra(Object extra) { public TestCase withWarning(String warning) { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, @@ -1839,6 +1884,8 @@ public TestCase withWarning(String warning) { */ public TestCase withBuildEvaluatorWarning(String warning) { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, @@ -1864,6 +1911,8 @@ private String[] addWarning(String[] warnings, String warning) { public TestCase withFoldingException(Class clazz, String message) { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, @@ -1886,6 +1935,8 @@ public TestCase withFoldingException(Class clazz, String me */ public TestCase withoutEvaluator() { return new TestCase( + source, + configuration, data, evaluatorToString, expectedType, diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java index 56e2197ce52ec..040ebe8f44004 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java @@ -7,18 +7,17 @@ package org.elasticsearch.xpack.esql.expression.function.scalar; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.esql.analysis.AnalyzerSettings; +import org.elasticsearch.xpack.esql.ConfigurationTestUtils; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; -import org.elasticsearch.xpack.esql.core.util.StringUtils; import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase; -import org.elasticsearch.xpack.esql.plugin.QueryPragmas; import org.elasticsearch.xpack.esql.session.Configuration; import java.util.List; import java.util.Map; +import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomConfiguration; +import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomTables; import static org.elasticsearch.xpack.esql.SerializationTestUtils.assertSerialization; public abstract class AbstractConfigurationFunctionTestCase extends AbstractScalarFunctionTestCase { @@ -35,29 +34,9 @@ public void testSerializationWithConfiguration() { assertSerialization(expr, config); - Configuration differentConfig = randomValueOtherThan(config, AbstractConfigurationFunctionTestCase::randomConfiguration); + Configuration differentConfig = randomValueOtherThan(config, () -> randomConfiguration(testCase.getSource().text(), randomTables())); Expression differentExpr = buildWithConfiguration(testCase.getSource(), testCase.getDataAsFields(), differentConfig); assertNotEquals(expr, differentExpr); } - - private static Configuration randomConfiguration() { - // TODO: Randomize the query and maybe the pragmas. - return new Configuration( - randomZone(), - randomLocale(random()), - randomBoolean() ? null : randomAlphaOfLength(randomInt(64)), - randomBoolean() ? null : randomAlphaOfLength(randomInt(64)), - QueryPragmas.EMPTY, - AnalyzerSettings.QUERY_RESULT_TRUNCATION_MAX_SIZE.getDefault(Settings.EMPTY), - AnalyzerSettings.QUERY_RESULT_TRUNCATION_DEFAULT_SIZE.getDefault(Settings.EMPTY), - StringUtils.EMPTY, - randomBoolean(), - Map.of(), - System.nanoTime(), - randomBoolean(), - AnalyzerSettings.QUERY_TIMESERIES_RESULT_TRUNCATION_MAX_SIZE.getDefault(Settings.EMPTY), - AnalyzerSettings.QUERY_TIMESERIES_RESULT_TRUNCATION_DEFAULT_SIZE.getDefault(Settings.EMPTY) - ); - } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java index 0067b022755e3..522fa91b3f364 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java @@ -56,7 +56,7 @@ public static Iterable parameters() { "DateExtractMillisEvaluator[value=Attribute[channel=1], chronoField=Attribute[channel=0], zone=Z]", DataType.LONG, equalTo(2023L) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ), new TestCaseSupplier( List.of(stringType, DataType.DATE_NANOS), @@ -68,7 +68,7 @@ public static Iterable parameters() { "DateExtractNanosEvaluator[value=Attribute[channel=1], chronoField=Attribute[channel=0], zone=Z]", DataType.LONG, equalTo(2023L) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ), new TestCaseSupplier( List.of(stringType, DataType.DATE_NANOS), @@ -80,7 +80,7 @@ public static Iterable parameters() { "DateExtractNanosEvaluator[value=Attribute[channel=1], chronoField=Attribute[channel=0], zone=Z]", DataType.LONG, equalTo(123456L) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ), new TestCaseSupplier( List.of(stringType, DataType.DATETIME), @@ -93,7 +93,8 @@ public static Iterable parameters() { "DateExtractMillisEvaluator[value=Attribute[channel=1], chronoField=Attribute[channel=0], zone=Z]", DataType.LONG, is(nullValue()) - ).withWarning("Line 1:1: evaluation of [source] failed, treating result as null. Only first 20 failures recorded.") + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) + .withWarning("Line 1:1: evaluation of [source] failed, treating result as null. Only first 20 failures recorded.") .withWarning( "Line 1:1: java.lang.IllegalArgumentException: " + "No enum constant java.time.temporal.ChronoField.NOT A UNIT" diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java index 1167b91a81e35..c7b2093f5cb63 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java @@ -13,6 +13,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.time.DateUtils; +import org.elasticsearch.xpack.esql.EsqlTestUtils; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.core.type.DataType; @@ -23,9 +24,13 @@ import java.time.Instant; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.function.Function; import java.util.function.Supplier; +import static java.util.stream.Collectors.toList; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.matchesPattern; public class DateFormatTests extends AbstractConfigurationFunctionTestCase { @@ -84,6 +89,10 @@ public static Iterable parameters() { (value) -> new BytesRef(EsqlDataTypeConverter.DEFAULT_DATE_TIME_FORMATTER.formatNanos(DateUtils.toLong((Instant) value))), List.of() ); + suppliers = TestCaseSupplier.mapTestCases( + suppliers, + testCase -> testCase.withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) + ); return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(true, suppliers); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java index 6b8b392f9d3f6..a45581df88254 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.time.DateUtils; +import org.elasticsearch.xpack.esql.ConfigurationTestUtils; import org.elasticsearch.xpack.esql.analysis.AnalyzerSettings; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.expression.FoldContext; @@ -62,7 +63,7 @@ public static Iterable parameters() { Matchers.startsWith("DayNameMillisEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(null) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ) ); @@ -78,7 +79,7 @@ private static List generateTest(String dateTime, String expec Matchers.startsWith("DayNameMillisEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(new BytesRef(expectedWeekDay)) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ), new TestCaseSupplier( List.of(DataType.DATE_NANOS), @@ -87,7 +88,7 @@ private static List generateTest(String dateTime, String expec Matchers.is("DayNameNanosEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(new BytesRef(expectedWeekDay)) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ) ); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/MonthNameTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/MonthNameTests.java index 13e91bf89627e..6f9bc3b577194 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/MonthNameTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/MonthNameTests.java @@ -72,7 +72,7 @@ public static Iterable parameters() { Matchers.startsWith("MonthNameMillisEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(null) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ) ); @@ -88,7 +88,7 @@ private static List generateTest(String dateTime, String expec Matchers.startsWith("MonthNameMillisEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(new BytesRef(expectedMonthName)) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ), new TestCaseSupplier( List.of(DataType.DATE_NANOS), @@ -97,7 +97,7 @@ private static List generateTest(String dateTime, String expec Matchers.is("MonthNameNanosEvaluator[val=Attribute[channel=0], zoneId=Z, locale=en_US]"), DataType.KEYWORD, equalTo(new BytesRef(expectedMonthName)) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ) ); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/NowTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/NowTests.java index b3c3ab874f90d..ab451d431fa2e 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/NowTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/NowTests.java @@ -42,7 +42,7 @@ public static Iterable parameters() { matchesPattern("LiteralsEvaluator\\[lit=.*]"), DataType.DATETIME, equalTo(TestCaseSupplier.TEST_CONFIGURATION.now().toInstant().toEpochMilli()) - ) + ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) ) ) ); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java index ebc9c0883acf5..01e53de4087eb 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java @@ -91,7 +91,7 @@ private static void suppliers(List suppliers, String name, Dat values.add(new TestCaseSupplier.TypedData(new BytesRef(value), type, "0")); String expectedValue = value.toLowerCase(EsqlTestUtils.TEST_CFG.locale()); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); })); suppliers.add(new TestCaseSupplier(name + " mv", List.of(type), () -> { List values = new ArrayList<>(); @@ -101,7 +101,7 @@ private static void suppliers(List suppliers, String name, Dat values.add(new TestCaseSupplier.TypedData(strings.stream().map(BytesRef::new).toList(), type, "0")); List expectedValue = strings.stream().map(s -> new BytesRef(s.toLowerCase(EsqlTestUtils.TEST_CFG.locale()))).toList(); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); })); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java index 539e51420faf3..5357e43a0304b 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java @@ -91,7 +91,7 @@ private static void supplier(List suppliers, String name, Data values.add(new TestCaseSupplier.TypedData(new BytesRef(value), type, "0")); String expectedValue = value.toUpperCase(EsqlTestUtils.TEST_CFG.locale()); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); })); suppliers.add(new TestCaseSupplier(name + " mv", List.of(type), () -> { List values = new ArrayList<>(); @@ -101,7 +101,7 @@ private static void supplier(List suppliers, String name, Data values.add(new TestCaseSupplier.TypedData(strings.stream().map(BytesRef::new).toList(), type, "0")); List expectedValue = strings.stream().map(s -> new BytesRef(s.toUpperCase(EsqlTestUtils.TEST_CFG.locale()))).toList(); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); })); } From 5dec7c3d9041eaf41dee56f8c59e3b47a038ac73 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Fri, 17 Oct 2025 16:21:21 +0000 Subject: [PATCH 5/5] [CI] Auto commit changes from spotless --- .../esql/expression/function/TestCaseSupplier.java | 8 +++----- .../scalar/AbstractConfigurationFunctionTestCase.java | 7 ++++--- .../function/scalar/date/DateExtractTests.java | 4 +++- .../function/scalar/date/DateFormatTests.java | 10 +--------- .../expression/function/scalar/date/DayNameTests.java | 1 - .../function/scalar/string/ToLowerTests.java | 8 ++++++-- .../function/scalar/string/ToUpperTests.java | 8 ++++++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java index e00a701ffe463..16aaf3e5ed26e 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java @@ -1577,11 +1577,9 @@ public static List mapTestCases( Collection suppliers, Function mapper ) { - return suppliers.stream().map(supplier -> - new TestCaseSupplier(supplier.name(), supplier.types(), () -> - mapper.apply(supplier.get()) - ) - ).toList(); + return suppliers.stream() + .map(supplier -> new TestCaseSupplier(supplier.name(), supplier.types(), () -> mapper.apply(supplier.get()))) + .toList(); } public static final class TestCase { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java index 040ebe8f44004..d1f98082fbb4b 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/AbstractConfigurationFunctionTestCase.java @@ -7,14 +7,12 @@ package org.elasticsearch.xpack.esql.expression.function.scalar; -import org.elasticsearch.xpack.esql.ConfigurationTestUtils; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase; import org.elasticsearch.xpack.esql.session.Configuration; import java.util.List; -import java.util.Map; import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomConfiguration; import static org.elasticsearch.xpack.esql.ConfigurationTestUtils.randomTables; @@ -34,7 +32,10 @@ public void testSerializationWithConfiguration() { assertSerialization(expr, config); - Configuration differentConfig = randomValueOtherThan(config, () -> randomConfiguration(testCase.getSource().text(), randomTables())); + Configuration differentConfig = randomValueOtherThan( + config, + () -> randomConfiguration(testCase.getSource().text(), randomTables()) + ); Expression differentExpr = buildWithConfiguration(testCase.getSource(), testCase.getDataAsFields(), differentConfig); assertNotEquals(expr, differentExpr); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java index 522fa91b3f364..f840d214c1bfd 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtractTests.java @@ -94,7 +94,9 @@ public static Iterable parameters() { DataType.LONG, is(nullValue()) ).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) - .withWarning("Line 1:1: evaluation of [source] failed, treating result as null. Only first 20 failures recorded.") + .withWarning( + "Line 1:1: evaluation of [source] failed, treating result as null. Only first 20 failures recorded." + ) .withWarning( "Line 1:1: java.lang.IllegalArgumentException: " + "No enum constant java.time.temporal.ChronoField.NOT A UNIT" diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java index c7b2093f5cb63..ef69daf268502 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.time.DateUtils; -import org.elasticsearch.xpack.esql.EsqlTestUtils; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.core.type.DataType; @@ -24,13 +23,9 @@ import java.time.Instant; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.function.Function; import java.util.function.Supplier; -import static java.util.stream.Collectors.toList; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.matchesPattern; public class DateFormatTests extends AbstractConfigurationFunctionTestCase { @@ -89,10 +84,7 @@ public static Iterable parameters() { (value) -> new BytesRef(EsqlDataTypeConverter.DEFAULT_DATE_TIME_FORMATTER.formatNanos(DateUtils.toLong((Instant) value))), List.of() ); - suppliers = TestCaseSupplier.mapTestCases( - suppliers, - testCase -> testCase.withConfiguration(TestCaseSupplier.TEST_CONFIGURATION) - ); + suppliers = TestCaseSupplier.mapTestCases(suppliers, testCase -> testCase.withConfiguration(TestCaseSupplier.TEST_CONFIGURATION)); return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(true, suppliers); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java index a45581df88254..f04fd3bf2c7b7 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DayNameTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.time.DateUtils; -import org.elasticsearch.xpack.esql.ConfigurationTestUtils; import org.elasticsearch.xpack.esql.analysis.AnalyzerSettings; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.expression.FoldContext; diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java index 01e53de4087eb..34910eba84c29 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLowerTests.java @@ -91,7 +91,9 @@ private static void suppliers(List suppliers, String name, Dat values.add(new TestCaseSupplier.TypedData(new BytesRef(value), type, "0")); String expectedValue = value.toLowerCase(EsqlTestUtils.TEST_CFG.locale()); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration( + TestCaseSupplier.TEST_CONFIGURATION + ); })); suppliers.add(new TestCaseSupplier(name + " mv", List.of(type), () -> { List values = new ArrayList<>(); @@ -101,7 +103,9 @@ private static void suppliers(List suppliers, String name, Dat values.add(new TestCaseSupplier.TypedData(strings.stream().map(BytesRef::new).toList(), type, "0")); List expectedValue = strings.stream().map(s -> new BytesRef(s.toLowerCase(EsqlTestUtils.TEST_CFG.locale()))).toList(); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration( + TestCaseSupplier.TEST_CONFIGURATION + ); })); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java index 5357e43a0304b..c9f8b5ab2791b 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpperTests.java @@ -91,7 +91,9 @@ private static void supplier(List suppliers, String name, Data values.add(new TestCaseSupplier.TypedData(new BytesRef(value), type, "0")); String expectedValue = value.toUpperCase(EsqlTestUtils.TEST_CFG.locale()); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(new BytesRef(expectedValue))).withConfiguration( + TestCaseSupplier.TEST_CONFIGURATION + ); })); suppliers.add(new TestCaseSupplier(name + " mv", List.of(type), () -> { List values = new ArrayList<>(); @@ -101,7 +103,9 @@ private static void supplier(List suppliers, String name, Data values.add(new TestCaseSupplier.TypedData(strings.stream().map(BytesRef::new).toList(), type, "0")); List expectedValue = strings.stream().map(s -> new BytesRef(s.toUpperCase(EsqlTestUtils.TEST_CFG.locale()))).toList(); - return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration(TestCaseSupplier.TEST_CONFIGURATION); + return new TestCaseSupplier.TestCase(values, expectedToString, type, equalTo(expectedValue)).withConfiguration( + TestCaseSupplier.TEST_CONFIGURATION + ); })); }