Skip to content

Commit c7ad022

Browse files
ES|QL: fix ENRICH validation for use of wildcards (#121911)
1 parent 9209341 commit c7ad022

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
@@ -795,9 +795,9 @@ public NamedExpression visitEnrichWithClause(EsqlBaseParser.EnrichWithClauseCont
795795

796796
private NamedExpression enrichFieldName(EsqlBaseParser.QualifiedNamePatternContext ctx) {
797797
return visitQualifiedNamePattern(ctx, ne -> {
798-
if (ne instanceof UnresolvedNamePattern up) {
798+
if (ne instanceof UnresolvedNamePattern || ne instanceof UnresolvedStar) {
799799
var src = ne.source();
800-
throw new ParsingException(src, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", up.pattern());
800+
throw new ParsingException(src, "Using wildcards [*] in ENRICH WITH projections is not allowed, found [{}]", src.text());
801801
}
802802
});
803803
}

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
@@ -422,7 +422,11 @@ public PlanFactory visitEnrichCommand(EsqlBaseParser.EnrichCommandContext ctx) {
422422
: matchField instanceof UnresolvedStar ? WILDCARD
423423
: null;
424424
if (patternString != null) {
425-
throw new ParsingException(source, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", patternString);
425+
throw new ParsingException(
426+
source,
427+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [{}]",
428+
patternString
429+
);
426430
}
427431

428432
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
@@ -1081,15 +1081,28 @@ public void testEnrich() {
10811081
processingCommand("enrich _" + mode.name() + ":countries ON country_code")
10821082
);
10831083

1084-
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed [foo*]");
1085-
expectError("from a | enrich countries on foo with bar*", "Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]");
1084+
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [foo*]");
1085+
expectError("from a | enrich countries on * ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
1086+
expectError(
1087+
"from a | enrich countries on foo with bar*",
1088+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1089+
);
1090+
expectError("from a | enrich countries on foo with *", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
10861091
expectError(
10871092
"from a | enrich countries on foo with x = bar* ",
1088-
"Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]"
1093+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1094+
);
1095+
expectError(
1096+
"from a | enrich countries on foo with x = * ",
1097+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10891098
);
10901099
expectError(
10911100
"from a | enrich countries on foo with x* = bar ",
1092-
"Using wildcards [*] in ENRICH WITH projections is not allowed [x*]"
1101+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [x*]"
1102+
);
1103+
expectError(
1104+
"from a | enrich countries on foo with * = bar ",
1105+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10931106
);
10941107
expectError(
10951108
"from a | enrich typo:countries on foo",
@@ -1973,7 +1986,7 @@ public void testParamInInvalidPosition() {
19731986
expectError(
19741987
"from idx1 | " + enrich,
19751988
List.of(paramAsPattern("f1", pattern), paramAsIdentifier("f2", "f.2"), paramAsIdentifier("f3", "f.3*")),
1976-
"Using wildcards [*] in ENRICH WITH projections is not allowed [" + pattern + "]"
1989+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [" + pattern + "]"
19771990
);
19781991
expectError(
19791992
"from idx1 | " + enrich,

0 commit comments

Comments
 (0)