Skip to content

ES|QL: Change FUSE KEY BY to receive a list of qualifiedName#139071

Merged
ioanatia merged 5 commits intoelastic:mainfrom
ioanatia:fuse_key_by_syntax
Dec 9, 2025
Merged

ES|QL: Change FUSE KEY BY to receive a list of qualifiedName#139071
ioanatia merged 5 commits intoelastic:mainfrom
ioanatia:fuse_key_by_syntax

Conversation

@ioanatia
Copy link
Contributor

@ioanatia ioanatia commented Dec 4, 2025

Previously KEY BY was using fields which is actually used by STATS ... BY.
However, what we actually want for the FUSE keys is a list of qualifiedName, whereas fields can also accept expressions like concat(field1, field2).

I checked if something like FUSE KEY BY concat(field1, field2) would actually work previously and it didn't - we still failed with a statement parser error, due to some mishandling ANTLR expression push mode for (.
So even if the syntax looked like it should allow something like concat(field1, field2), in reality this does not actually work even right now on main.

@ioanatia ioanatia added >bug Team:Search - Relevance The Search organization Search Relevance team :Search Relevance/ES|QL Search functionality in ES|QL v9.3.0 labels Dec 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @ioanatia, I've created a changelog YAML for you.

@ioanatia ioanatia marked this pull request as ready for review December 8, 2025 14:53
@elasticsearchmachine elasticsearchmachine added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch and removed Team:Search - Relevance The Search organization Search Relevance team labels Dec 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)


expectError(queryPrefix + " | FUSE GROUP BY foo SCORE BY my_score LINEAR", "line 1:111: extraneous input 'LINEAR' expecting <EOF>");

expectError(queryPrefix + " | FUSE KEY BY CONCAT(key1, key2)", "line 1:93: token recognition error at: '('");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The KEY BY syntax is exercised in many existing tests already, see for example:

FROM books METADATA _id, _score
| FORK ( WHERE title:"Tolkien" | SORT _score, _id DESC | LIMIT 3
| EVAL new_id = CONCAT(_id, _id) | DROP _id)
( WHERE author:"Tolkien" | SORT _score, _id DESC | LIMIT 3 | EVAL new_id = CONCAT(_id, _id) | DROP _id)
| EVAL new_fork = CASE (_fork == "fork1", "A", "B")
| EVAL new_score = _score * 2
| DROP _fork, _score
| FUSE rrf SCORE BY new_score KEY BY new_id GROUP BY new_fork WITH {"rank_constant": 60, "weights": { "fork1": 0.3, "fork2": 0.7 } }

so I only need to add a statement tests to check that we raise a syntax error when the wrong syntax is used with KEY BY

Copy link
Contributor

@afoucret afoucret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This grammar change is quite straightforward.

Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! 👍

@ioanatia ioanatia merged commit 1400cd3 into elastic:main Dec 9, 2025
34 checks passed
@ioanatia ioanatia deleted the fuse_key_by_syntax branch December 9, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Relevance/ES|QL Search functionality in ES|QL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.3.0

4 participants