Skip to content

Commit

Permalink
ES|QL: make capabilities an enum (elastic#109935)
Browse files Browse the repository at this point in the history
So that registration is automatic.

Let's merge it after
elastic#109926 to make sure all
the tests are good
  • Loading branch information
luigidellaquila authored Jun 21, 2024
1 parent 50bdb9c commit 57f4870
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/**
Expand All @@ -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": [<values>]}}.
*/
private static final String TABLES_TYPES = "tables_types";
/**
* Support for the syntax {@code "tables": {"type": [<values>]}}.
*/
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<String> CAPABILITIES = capabilities();

private static Set<String> capabilities() {
List<String> 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());
}
}

/*
Expand All @@ -110,7 +118,6 @@ private static Set<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 57f4870

Please sign in to comment.