Skip to content

Commit 27d1c6e

Browse files
ES|QL: fix ENRICH validation for use of wildcards (#121911) (#122021)
1 parent b35a923 commit 27d1c6e

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

docs/changelog/121911.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121911
2+
summary: Fix ENRICH validation for use of wildcards
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ public NamedExpression visitEnrichWithClause(EsqlBaseParser.EnrichWithClauseCont
731731

732732
private NamedExpression enrichFieldName(EsqlBaseParser.QualifiedNamePatternContext ctx) {
733733
return visitQualifiedNamePattern(ctx, ne -> {
734-
if (ne instanceof UnresolvedNamePattern up) {
734+
if (ne instanceof UnresolvedNamePattern || ne instanceof UnresolvedStar) {
735735
var src = ne.source();
736-
throw new ParsingException(src, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", up.pattern());
736+
throw new ParsingException(src, "Using wildcards [*] in ENRICH WITH projections is not allowed, found [{}]", src.text());
737737
}
738738
});
739739
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ public PlanFactory visitEnrichCommand(EsqlBaseParser.EnrichCommandContext ctx) {
433433
: matchField instanceof UnresolvedStar ? WILDCARD
434434
: null;
435435
if (patternString != null) {
436-
throw new ParsingException(source, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", patternString);
436+
throw new ParsingException(
437+
source,
438+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [{}]",
439+
patternString
440+
);
437441
}
438442

439443
List<NamedExpression> keepClauses = visitList(this, ctx.enrichWithClause(), NamedExpression.class);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,15 +1064,28 @@ public void testEnrich() {
10641064
processingCommand("enrich _" + mode.name() + ":countries ON country_code")
10651065
);
10661066

1067-
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed [foo*]");
1068-
expectError("from a | enrich countries on foo with bar*", "Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]");
1067+
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [foo*]");
1068+
expectError("from a | enrich countries on * ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
1069+
expectError(
1070+
"from a | enrich countries on foo with bar*",
1071+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1072+
);
1073+
expectError("from a | enrich countries on foo with *", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
10691074
expectError(
10701075
"from a | enrich countries on foo with x = bar* ",
1071-
"Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]"
1076+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1077+
);
1078+
expectError(
1079+
"from a | enrich countries on foo with x = * ",
1080+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10721081
);
10731082
expectError(
10741083
"from a | enrich countries on foo with x* = bar ",
1075-
"Using wildcards [*] in ENRICH WITH projections is not allowed [x*]"
1084+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [x*]"
1085+
);
1086+
expectError(
1087+
"from a | enrich countries on foo with * = bar ",
1088+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10761089
);
10771090
expectError(
10781091
"from a | enrich typo:countries on foo",
@@ -1970,7 +1983,7 @@ public void testParamInInvalidPosition() {
19701983
expectError(
19711984
"from idx1 | " + enrich,
19721985
List.of(paramAsPattern("f1", pattern), paramAsIdentifier("f2", "f.2"), paramAsIdentifier("f3", "f.3*")),
1973-
"Using wildcards [*] in ENRICH WITH projections is not allowed [" + pattern + "]"
1986+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [" + pattern + "]"
19741987
);
19751988
expectError(
19761989
"from idx1 | " + enrich,

0 commit comments

Comments
 (0)