Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

afoucret
Copy link
Contributor

@afoucret afoucret commented Jun 20, 2025

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 error

"mismatched input '}' expecting QUOTED_STRING"

I 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 now Duplicated 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

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.1.0 labels Jun 20, 2025
@afoucret afoucret changed the title MapExpression improvements. [ES|QL] MapExpression improvements. Jun 20, 2025
@afoucret afoucret added auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v8.19.0 >non-issue labels Jun 20, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jun 20, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Jun 20, 2025
@@ -49,14 +49,15 @@ primaryExpression

functionExpression
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)* (COMMA mapExpression)?))? RP
| functionName LP mapExpression? RP
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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();
Copy link
Contributor Author

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());
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants