Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/117872.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 117872
summary: "Optional named arguments for function in map - option #1"
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Set<String> getSupportedAnnotationTypes() {
"org.elasticsearch.injection.guice.Inject",
"org.elasticsearch.xpack.esql.expression.function.FunctionInfo",
"org.elasticsearch.xpack.esql.expression.function.Param",
"org.elasticsearch.xpack.esql.expression.function.MapParam",
"org.elasticsearch.rest.ServerlessScope",
"org.elasticsearch.xcontent.ParserConstructor",
"org.elasticsearch.core.UpdateForV9",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Tests to validate maps as inputs to functions, these functions are under snapshot only

mapCount
required_capability: optional_named_argument_map_for_function
ROW x = 1
| EVAL c = map_count({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
;

x:integer |c:long
1 |4
;

mapCountIndex
required_capability: optional_named_argument_map_for_function
FROM employees
| EVAL c = map_count({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
| KEEP emp_no, c
| SORT emp_no
| LIMIT 1
;

emp_no:integer |c:long
10001 |4
;


mapKeys
required_capability: optional_named_argument_map_for_function
ROW x = 1
| EVAL k = map_keys({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
;

x:integer |k:keyword
1 |"option1, option2, option3, option4"
;

mapKeysIndex
required_capability: optional_named_argument_map_for_function
FROM employees
| EVAL k = map_keys({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
| KEEP emp_no, k
| SORT emp_no
| LIMIT 1
;

emp_no:integer |k:keyword
10001 |"option1, option2, option3, option4"
;

mapValues
required_capability: optional_named_argument_map_for_function
ROW x = 1
| EVAL v = map_values({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
;

x:integer |v:keyword
1 |"value1, 2, 3.0, true"
;

mapKeysIndex
required_capability: optional_named_argument_map_for_function
FROM employees
| EVAL v = map_values({"option1":"value1", "option2":2, "option3":3.0, "option4":true})
| KEEP emp_no, v
| SORT emp_no
| LIMIT 1
;

emp_no:integer |v:keyword
10001 |"value1, 2, 3.0, true"
;
3 changes: 3 additions & 0 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ ASTERISK : '*';
SLASH : '/';
PERCENT : '%';

LEFT_BRACES : {this.isDevVersion()}? '{';
RIGHT_BRACES : {this.isDevVersion()}? '}';

NESTED_WHERE : WHERE -> type(WHERE);

NAMED_OR_POSITIONAL_PARAM
Expand Down
15 changes: 14 additions & 1 deletion x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,26 @@ primaryExpression
;

functionExpression
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)*))? RP
: functionName LP (ASTERISK | (functionArgument (COMMA functionArgument)*))? RP
;

functionName
: identifierOrParameter
;

functionArgument
: booleanExpression #functionArgumentDefault
| {this.isDevVersion()}? LEFT_BRACES namedConstants RIGHT_BRACES #functionArgumentWithName
;

namedConstants
: namedConstant (COMMA namedConstant)*
;

namedConstant
: key=string COLON value=constant
;

dataType
: identifier #toDataType
;
Expand Down
136 changes: 69 additions & 67 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.tokens

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,12 @@ public enum Cap {
/**
* Support the "METADATA _score" directive to enable _score column.
*/
METADATA_SCORE(Build.current().isSnapshot());
METADATA_SCORE(Build.current().isSnapshot()),

/**
* Support named argument for function in map format.
*/
OPTIONAL_NAMED_ARGUMENT_MAP_FOR_FUNCTION(Build.current().isSnapshot());

private final boolean enabled;

Expand Down
Loading