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 ebfcdacd7587a..9b759a49eab4e 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 @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Set; /** @@ -22,83 +23,90 @@ * {@link RestNodesCapabilitiesAction} and we use them to enable tests. */ public class EsqlCapabilities { - /** - * Support for function {@code CBRT}. Done in #108574. - */ - private static final String FN_CBRT = "fn_cbrt"; + public enum Cap { + /** + * Support for function {@code CBRT}. Done in #108574. + */ + FN_CBRT, - /** - * Support for {@code MV_APPEND} function. #107001 - */ - private static final String FN_MV_APPEND = "fn_mv_append"; + /** + * Support for {@code MV_APPEND} function. #107001 + */ + FN_MV_APPEND, - /** - * Support for function {@code IP_PREFIX}. - */ - private static final String FN_IP_PREFIX = "fn_ip_prefix"; + /** + * Support for function {@code IP_PREFIX}. + */ + FN_IP_PREFIX, - /** - * Fix on function {@code SUBSTRING} that makes it not return null on empty strings. - */ - private static final String FN_SUBSTRING_EMPTY_NULL = "fn_substring_empty_null"; + /** + * Fix on function {@code SUBSTRING} that makes it not return null on empty strings. + */ + FN_SUBSTRING_EMPTY_NULL, - /** - * Support for aggregation function {@code TOP_LIST}. - */ - private static final String AGG_TOP_LIST = "agg_top_list"; + /** + * Support for aggregation function {@code TOP_LIST}. + */ + AGG_TOP_LIST, - /** - * Optimization for ST_CENTROID changed some results in cartesian data. #108713 - */ - private static final String ST_CENTROID_AGG_OPTIMIZED = "st_centroid_agg_optimized"; + /** + * Optimization for ST_CENTROID changed some results in cartesian data. #108713 + */ + ST_CENTROID_AGG_OPTIMIZED, - /** - * Support for requesting the "_ignored" metadata field. - */ - private static final String METADATA_IGNORED_FIELD = "metadata_field_ignored"; + /** + * Support for requesting the "_ignored" metadata field. + */ + METADATA_IGNORED_FIELD, - /** - * Support for the syntax {@code "tables": {"type": []}}. - */ - private static final String TABLES_TYPES = "tables_types"; + /** + * Support for the syntax {@code "tables": {"type": []}}. + */ + TABLES_TYPES(true), - /** - * Support for requesting the "REPEAT" command. - */ - private static final String REPEAT = "repeat"; + /** + * Support for requesting the "REPEAT" command. + */ + REPEAT, - /** - * Cast string literals to datetime in addition and subtraction when the other side is a date or time interval. - */ - public static final String STRING_LITERAL_AUTO_CASTING_TO_DATETIME_ADD_SUB = "string_literal_auto_casting_to_datetime_add_sub"; + /** + * Cast string literals to datetime in addition and subtraction when the other side is a date or time interval. + */ + STRING_LITERAL_AUTO_CASTING_TO_DATETIME_ADD_SUB, - /** - * Support multiple field mappings if appropriate conversion function is used (union types) - */ - public static final String UNION_TYPES = "union_types"; + /** + * Support for named or positional parameters in EsqlQueryRequest. + */ + NAMED_POSITIONAL_PARAMETER, - /** - * Support for named or positional parameters in EsqlQueryRequest. - */ - private static final String NAMED_POSITIONAL_PARAMETER = "named_positional_parameter"; + /** + * Support multiple field mappings if appropriate conversion function is used (union types) + */ + UNION_TYPES; + + Cap() { + snapshotOnly = false; + }; + + Cap(boolean snapshotOnly) { + this.snapshotOnly = snapshotOnly; + }; + + public String capabilityName() { + return name().toLowerCase(Locale.ROOT); + } + + private final boolean snapshotOnly; + } public static final Set CAPABILITIES = capabilities(); private static Set capabilities() { List caps = new ArrayList<>(); - caps.add(FN_CBRT); - caps.add(FN_IP_PREFIX); - caps.add(FN_SUBSTRING_EMPTY_NULL); - caps.add(AGG_TOP_LIST); - caps.add(ST_CENTROID_AGG_OPTIMIZED); - caps.add(METADATA_IGNORED_FIELD); - caps.add(FN_MV_APPEND); - caps.add(REPEAT); - caps.add(UNION_TYPES); - caps.add(NAMED_POSITIONAL_PARAMETER); - - if (Build.current().isSnapshot()) { - caps.add(TABLES_TYPES); + for (Cap cap : Cap.values()) { + if (Build.current().isSnapshot() || cap.snapshotOnly == false) { + caps.add(cap.capabilityName()); + } } /* @@ -110,7 +118,6 @@ private static Set capabilities() { for (NodeFeature feature : new EsqlFeatures().getHistoricalFeatures().keySet()) { caps.add(cap(feature)); } - caps.add(STRING_LITERAL_AUTO_CASTING_TO_DATETIME_ADD_SUB); return Set.copyOf(caps); } 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 960f341857b1f..fd161c8d63871 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 @@ -229,7 +229,10 @@ public final void test() throws Throwable { assumeFalse("metadata fields aren't supported", testCase.requiredCapabilities.contains(cap(EsqlFeatures.METADATA_FIELDS))); assumeFalse("enrich can't load fields in csv tests", testCase.requiredCapabilities.contains(cap(EsqlFeatures.ENRICH_LOAD))); assumeFalse("can't load metrics in csv tests", testCase.requiredCapabilities.contains(cap(EsqlFeatures.METRICS_SYNTAX))); - assumeFalse("multiple indices aren't supported", testCase.requiredCapabilities.contains(EsqlCapabilities.UNION_TYPES)); + assumeFalse( + "multiple indices aren't supported", + testCase.requiredCapabilities.contains(EsqlCapabilities.Cap.UNION_TYPES.capabilityName()) + ); if (Build.current().isSnapshot()) { assertThat(