From f186bec0660de1f50967c9bec17bd8ef07d2bdf0 Mon Sep 17 00:00:00 2001 From: Craig Taverner Date: Fri, 19 Dec 2025 13:01:00 +0100 Subject: [PATCH 1/3] Support generating inline_cast.json again This is still using the old format. There is also an operators/cast.json file which could be extended to provide the same information in a more consistent way with the rest of the operators. --- .../esql/kibana/definition/inline_cast.json | 27 +++++++++++++++++++ .../xpack/esql/CommandDocsTests.java | 5 ---- .../expression/function/DocsV3Support.java | 23 +++++++--------- .../esql/parser/StatementParserTests.java | 24 ++++++++++++++--- 4 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 docs/reference/query-languages/esql/kibana/definition/inline_cast.json diff --git a/docs/reference/query-languages/esql/kibana/definition/inline_cast.json b/docs/reference/query-languages/esql/kibana/definition/inline_cast.json new file mode 100644 index 0000000000000..e22f471f1f618 --- /dev/null +++ b/docs/reference/query-languages/esql/kibana/definition/inline_cast.json @@ -0,0 +1,27 @@ +{ + "aggregate_metric_double" : "to_aggregate_metric_double", + "bool" : "to_boolean", + "boolean" : "to_boolean", + "cartesian_point" : "to_cartesianpoint", + "cartesian_shape" : "to_cartesianshape", + "date" : "to_datetime", + "date_nanos" : "to_date_nanos", + "date_period" : "to_dateperiod", + "datetime" : "to_datetime", + "dense_vector" : "to_dense_vector", + "double" : "to_double", + "geo_point" : "to_geopoint", + "geo_shape" : "to_geoshape", + "geohash" : "to_geohash", + "geohex" : "to_geohex", + "geotile" : "to_geotile", + "int" : "TO_INTEGER", + "integer" : "TO_INTEGER", + "ip" : "TO_IP", + "keyword" : "to_string", + "long" : "TO_LONG", + "string" : "to_string", + "time_duration" : "to_timeduration", + "unsigned_long" : "to_unsigned_long", + "version" : "to_version" +} diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CommandDocsTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CommandDocsTests.java index 9e0d3c1594539..b44d32781bb6d 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CommandDocsTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CommandDocsTests.java @@ -58,11 +58,6 @@ public TestDocsV3Support() { super("commands", "commands", CommandDocsTests.class, null, callbacksFromSystemProperty()); } - @Override - protected void renderSignature() throws IOException { - // Not implemented - } - @Override protected void renderDocs() throws IOException { // Not implemented diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java index 375716e7ebcbc..aba18b8d66f0a 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java @@ -560,13 +560,18 @@ void writeToTempSnippetsDir(String subdir, String str) throws IOException { callbacks.write(dir, name, "md", str, false); } - void writeToTempKibanaDir(String subdir, String extension, String str) throws IOException { + protected void writeToTempKibanaDir(String subdir, String extension, String str) throws IOException { // We have to write to a tempdir because it’s all test are allowed to write to. Gradle can move them. - Path dir = PathUtils.get(System.getProperty("java.io.tmpdir")).resolve("esql").resolve("kibana").resolve(subdir).resolve(category); + Path dir = PathUtils.get(System.getProperty("java.io.tmpdir")).resolve("esql").resolve("kibana").resolve(subdir); + if (category != null) { + dir = dir.resolve(category); + } callbacks.write(dir, name, extension, str, true); } - protected abstract void renderSignature() throws IOException; + public void renderSignature() throws IOException { + // Only functions and operators currently have signatures to render, so only they should override this method. + } protected abstract void renderDocs() throws Exception; @@ -586,7 +591,7 @@ private FunctionDocsSupport(String name, Class testClass, Callbacks callbacks } @Override - protected void renderSignature() throws IOException { + public void renderSignature() throws IOException { if (callbacks.supportsRendering() == false) { return; } @@ -1003,11 +1008,6 @@ public CommandsDocsSupport( this.observabilityTier = null; } - @Override - public void renderSignature() throws IOException { - // Unimplemented until we make command docs dynamically generated - } - @Override public void renderDocs() throws Exception { // Currently we only render either signatures or kibana definition files, @@ -1094,11 +1094,6 @@ public SettingsDocsSupport(QuerySettingDef setting, Class testClass, Callb this.setting = setting; } - @Override - public void renderSignature() throws IOException { - // Unimplemented until we make setting docs dynamically generated - } - @Override public void renderDocs() throws Exception { // TODO docs for settings diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java index cc2458f62fe21..6896b2a265856 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java @@ -9,6 +9,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.Build; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.settings.Settings; @@ -32,6 +33,7 @@ import org.elasticsearch.xpack.esql.core.type.DataType; import org.elasticsearch.xpack.esql.expression.Order; import org.elasticsearch.xpack.esql.expression.UnresolvedNamePattern; +import org.elasticsearch.xpack.esql.expression.function.DocsV3Support; import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry; import org.elasticsearch.xpack.esql.expression.function.UnresolvedFunction; import org.elasticsearch.xpack.esql.expression.function.aggregate.FilteredExpression; @@ -87,6 +89,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.stream.Stream; @@ -4221,9 +4224,7 @@ public void testInlineCast() throws IOException { .resolve("definition"); Files.createDirectories(dir); Path file = dir.resolve("inline_cast.json"); - try (XContentBuilder report = new XContentBuilder(JsonXContent.jsonXContent, Files.newOutputStream(file))) { - report.humanReadable(true).prettyPrint(); - report.startObject(); + try (XContentBuilder report = JsonXContent.contentBuilder().humanReadable(true).prettyPrint().lfAtEnd().startObject()) { List namesAndAliases = new ArrayList<>(DataType.namesAndAliases()); if (EsqlCapabilities.Cap.SPATIAL_GRID_TYPES.isEnabled() == false) { // Some types do not have a converter function if the capability is disabled @@ -4243,11 +4244,26 @@ public void testInlineCast() throws IOException { assertThat(functionCall.dataType(), equalTo(expectedType)); report.field(nameOrAlias, registry.snapshotRegistry().functionName(functionCall.getClass())); } - report.endObject(); + String rendered = Strings.toString(report.endObject()); + (new TestInlineCastDocsSupport(rendered)).renderDocs(); } logger.info("Wrote to file: {}", file); } + private static class TestInlineCastDocsSupport extends DocsV3Support { + private final String rendered; + + protected TestInlineCastDocsSupport(String rendered) { + super(null, "inline_cast", StatementParserTests.class, Set::of, new DocsV3Support.WriteCallbacks()); + this.rendered = rendered; + } + + @Override + protected void renderDocs() throws IOException { + this.writeToTempKibanaDir("definition", "json", rendered); + } + } + public void testTooBigQuery() { StringBuilder query = new StringBuilder("FROM foo | EVAL a = a"); while (query.length() < EsqlParser.MAX_LENGTH) { From 8703c369f9a0636338a11303ef99cd7b803b392d Mon Sep 17 00:00:00 2001 From: Craig Taverner Date: Fri, 19 Dec 2025 16:08:14 +0100 Subject: [PATCH 2/3] Make functions lowercase for consistency --- .../esql/kibana/definition/inline_cast.json | 8 ++++---- .../xpack/esql/parser/StatementParserTests.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/reference/query-languages/esql/kibana/definition/inline_cast.json b/docs/reference/query-languages/esql/kibana/definition/inline_cast.json index e22f471f1f618..7b76b37367f44 100644 --- a/docs/reference/query-languages/esql/kibana/definition/inline_cast.json +++ b/docs/reference/query-languages/esql/kibana/definition/inline_cast.json @@ -15,11 +15,11 @@ "geohash" : "to_geohash", "geohex" : "to_geohex", "geotile" : "to_geotile", - "int" : "TO_INTEGER", - "integer" : "TO_INTEGER", - "ip" : "TO_IP", + "int" : "to_integer", + "integer" : "to_integer", + "ip" : "to_ip", "keyword" : "to_string", - "long" : "TO_LONG", + "long" : "to_long", "string" : "to_string", "time_duration" : "to_timeduration", "unsigned_long" : "to_unsigned_long", diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java index 6896b2a265856..efbc8d35f4a65 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java @@ -88,6 +88,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.Function; @@ -4242,7 +4243,7 @@ public void testInlineCast() throws IOException { org.elasticsearch.xpack.esql.core.expression.function.Function functionCall = (org.elasticsearch.xpack.esql.core.expression.function.Function) row.fields().get(0).child(); assertThat(functionCall.dataType(), equalTo(expectedType)); - report.field(nameOrAlias, registry.snapshotRegistry().functionName(functionCall.getClass())); + report.field(nameOrAlias, registry.snapshotRegistry().functionName(functionCall.getClass()).toLowerCase(Locale.ROOT)); } String rendered = Strings.toString(report.endObject()); (new TestInlineCastDocsSupport(rendered)).renderDocs(); From 0d9936916cf81516ee9f90c883f674cde483ff85 Mon Sep 17 00:00:00 2001 From: Craig Taverner Date: Fri, 19 Dec 2025 16:11:58 +0100 Subject: [PATCH 3/3] Cleaner option start/end --- .../xpack/esql/parser/StatementParserTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java index efbc8d35f4a65..2ec01bd66c951 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java @@ -4225,7 +4225,8 @@ public void testInlineCast() throws IOException { .resolve("definition"); Files.createDirectories(dir); Path file = dir.resolve("inline_cast.json"); - try (XContentBuilder report = JsonXContent.contentBuilder().humanReadable(true).prettyPrint().lfAtEnd().startObject()) { + try (XContentBuilder report = JsonXContent.contentBuilder().humanReadable(true).prettyPrint().lfAtEnd()) { + report.startObject(); List namesAndAliases = new ArrayList<>(DataType.namesAndAliases()); if (EsqlCapabilities.Cap.SPATIAL_GRID_TYPES.isEnabled() == false) { // Some types do not have a converter function if the capability is disabled @@ -4245,7 +4246,8 @@ public void testInlineCast() throws IOException { assertThat(functionCall.dataType(), equalTo(expectedType)); report.field(nameOrAlias, registry.snapshotRegistry().functionName(functionCall.getClass()).toLowerCase(Locale.ROOT)); } - String rendered = Strings.toString(report.endObject()); + report.endObject(); + String rendered = Strings.toString(report); (new TestInlineCastDocsSupport(rendered)).renderDocs(); } logger.info("Wrote to file: {}", file);