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..7b76b37367f44 --- /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..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 @@ -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; @@ -86,7 +88,9 @@ 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; import java.util.stream.Stream; @@ -4221,8 +4225,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(); + 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) { @@ -4241,13 +4244,29 @@ 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)); } report.endObject(); + String rendered = Strings.toString(report); + (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) {