Skip to content

Commit fe4c41e

Browse files
authored
ES|QL: Configurable score, key and group by columns for FUSE (#135079)
1 parent e9ae5ea commit fe4c41e

File tree

24 files changed

+3288
-2576
lines changed

24 files changed

+3288
-2576
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/fuse.csv-spec

Lines changed: 317 additions & 16 deletions
Large diffs are not rendered by default.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/rerank.csv-spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ book_no:keyword | title:text | author
204204

205205
reranker after FUSE
206206
required_capability: fork_v9
207-
required_capability: fuse_v3
207+
required_capability: fuse_v4
208208
required_capability: match_operator_colon
209209
required_capability: rerank
210210

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/FuseIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
2828

2929
@Before
3030
public void setupIndex() {
31-
assumeTrue("requires FUSE capability", EsqlCapabilities.Cap.FUSE_V3.isEnabled());
31+
assumeTrue("requires FUSE capability", EsqlCapabilities.Cap.FUSE_V4.isEnabled());
3232
createAndPopulateIndex();
3333
}
3434

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/FuseWithInvalidLicenseIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
3131

3232
@Before
3333
public void setupIndex() {
34-
assumeTrue("requires FUSE capability", EsqlCapabilities.Cap.FUSE_V3.isEnabled());
34+
assumeTrue("requires FUSE capability", EsqlCapabilities.Cap.FUSE_V4.isEnabled());
3535
var indexName = "test";
3636
var client = client().admin().indices();
3737
var CreateRequest = client.prepareCreate(indexName)

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.tokens

Lines changed: 46 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ insistCommand
338338
;
339339

340340
fuseCommand
341-
: DEV_FUSE (fuseType=identifier)? fuseOptions=commandNamedParameters
341+
: DEV_FUSE (fuseType=identifier)? (fuseConfiguration)*
342+
;
343+
344+
fuseConfiguration
345+
: SCORE BY score=qualifiedName
346+
| KEY BY key=fields
347+
| GROUP BY group=qualifiedName
348+
| WITH options=mapExpression
342349
;
343350

344351
setCommand

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.tokens

Lines changed: 46 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/antlr/lexer/Fuse.g4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ FUSE_PIPE : PIPE -> type(PIPE), popMode;
1414
// explicit popMode of RP to allow FUSE in FORK branches
1515
FUSE_RP : RP -> type(RP), popMode, popMode;
1616

17+
GROUP: 'group';
18+
SCORE: 'score';
19+
KEY : 'key';
20+
1721
FUSE_WITH: WITH -> type(WITH), popMode, pushMode(EXPRESSION_MODE);
1822
FUSE_COMMA: COMMA -> type(COMMA);
23+
FUSE_BY: BY -> type(BY);
1924
FUSE_QUOTED_IDENTIFIER: QUOTED_IDENTIFIER -> type(QUOTED_IDENTIFIER);
2025
FUSE_UNQUOTED_IDENTIFIER: UNQUOTED_IDENTIFIER -> type(UNQUOTED_IDENTIFIER);
2126
FUSE_LINE_COMMENT: LINE_COMMENT -> channel(HIDDEN);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ public enum Cap {
13571357
/**
13581358
* FUSE command
13591359
*/
1360-
FUSE_V3(Build.current().isSnapshot()),
1360+
FUSE_V4(Build.current().isSnapshot()),
13611361

13621362
/**
13631363
* Support improved behavior for LIKE operator when used with index fields.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,14 +1026,19 @@ private LogicalPlan resolveFuse(Fuse fuse, List<Attribute> childrenOutput) {
10261026
discriminator = maybeResolveAttribute((UnresolvedAttribute) discriminator, childrenOutput);
10271027
}
10281028

1029-
List<NamedExpression> groupings = fuse.groupings()
1029+
List<NamedExpression> keys = fuse.keys()
10301030
.stream()
10311031
.map(attr -> attr instanceof UnresolvedAttribute ? maybeResolveAttribute((UnresolvedAttribute) attr, childrenOutput) : attr)
10321032
.toList();
10331033

1034-
// some attributes were unresolved - we return Fuse here so that the Verifier can raise an error message
1035-
if (score instanceof UnresolvedAttribute || discriminator instanceof UnresolvedAttribute) {
1036-
return new Fuse(fuse.source(), fuse.child(), score, discriminator, groupings, fuse.fuseType(), fuse.options());
1034+
// some attributes were unresolved or the wrong type
1035+
// we return Fuse here so that the Verifier can raise an error message
1036+
if (score instanceof UnresolvedAttribute
1037+
|| (score.resolved() && score.dataType() != DOUBLE)
1038+
|| discriminator instanceof UnresolvedAttribute
1039+
|| (discriminator.resolved() && DataType.isString(discriminator.dataType()) == false)
1040+
|| keys.stream().allMatch(attr -> attr.resolved() && DataType.isString(attr.dataType())) == false) {
1041+
return new Fuse(fuse.source(), fuse.child(), score, discriminator, keys, fuse.fuseType(), fuse.options());
10371042
}
10381043

10391044
LogicalPlan scoreEval = new FuseScoreEval(source, fuse.child(), score, discriminator, fuse.fuseType(), fuse.options());
@@ -1051,7 +1056,7 @@ private LogicalPlan resolveFuse(Fuse fuse, List<Attribute> childrenOutput) {
10511056
aggregates.add(new Alias(source, attr.name(), new Values(source, attr, aggFilter)));
10521057
}
10531058

1054-
return resolveAggregate(new Aggregate(source, scoreEval, new ArrayList<>(groupings), aggregates), childrenOutput);
1059+
return resolveAggregate(new Aggregate(source, scoreEval, new ArrayList<>(keys), aggregates), childrenOutput);
10551060
}
10561061

10571062
private Attribute maybeResolveAttribute(UnresolvedAttribute ua, List<Attribute> childrenOutput) {

0 commit comments

Comments
 (0)