-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[ES|QL] MapExpression improvements. #129759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Pinging @elastic/es-analytical-engine (Team:Analytics) |
@@ -49,14 +49,15 @@ primaryExpression | |||
|
|||
functionExpression | |||
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)* (COMMA mapExpression)?))? RP | |||
| functionName LP mapExpression? RP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ A small grammar change to allow a function that have only optional params which is currently impossible
my_function({"foo": "bar"})
@@ -193,6 +193,10 @@ public static Literal keyword(Source source, String literal) { | |||
return new Literal(source, BytesRefs.toBytesRef(literal), KEYWORD); | |||
} | |||
|
|||
public static Literal keyword(Source source, Collection<String> literal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Make it easier to instantiate multivalued strings literals, especially in tests
@@ -612,7 +613,7 @@ public Expression visitFunctionExpression(EsqlBaseParser.FunctionExpressionConte | |||
List<Expression> args = expressions(ctx.booleanExpression()); | |||
if (ctx.mapExpression() != null) { | |||
MapExpression mapArg = visitMapExpression(ctx.mapExpression()); | |||
args.add(mapArg); | |||
args = Stream.concat(args.stream(), Stream.of(mapArg)).toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Sometimes the list is read only (e.g visitList
use emptyList
).
"Invalid named function argument [{}], empty key is not supported", | ||
entry.getText() | ||
); | ||
throw new ParsingException(source(ctx), "Invalid named argument [{}], empty key is not supported", entry.getText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Wording changes to remove reference to functions.
Some improvements on the optional parameters.
Allow empty map
Currently when using an empty map to provide named parameters to a function (e.g.
match(tilte, "query", {})
the user can see the following parser errorI think we should allow the user to provide an empty map without failing, especially with such a message that is difficult to read.
Remove reference to function in the parser error message:
Example:
Duplicated function arguments with the same ...
is nowDuplicated function arguments with the same ...
By doing this we can reuse the mapExpression outside of a function which is legit IMHO.
See POC of implementing RERANK/COMPLETION OPTIONS for an example of usage in command syntax
More tests
Also I added more tests for the parsing of MapExpression directly in ExpressionTests