Skip to content

Commit e1176cd

Browse files
ES|QL: fix ENRICH validation for use of wildcards (#121911) (#122020)
1 parent 3a298fc commit e1176cd

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

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

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
@@ -426,7 +426,11 @@ public PlanFactory visitEnrichCommand(EsqlBaseParser.EnrichCommandContext ctx) {
426426
: matchField instanceof UnresolvedStar ? WILDCARD
427427
: null;
428428
if (patternString != null) {
429-
throw new ParsingException(source, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", patternString);
429+
throw new ParsingException(
430+
source,
431+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [{}]",
432+
patternString
433+
);
430434
}
431435

432436
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
@@ -1055,15 +1055,28 @@ public void testEnrich() {
10551055
processingCommand("enrich _" + mode.name() + ":countries ON country_code")
10561056
);
10571057

1058-
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed [foo*]");
1059-
expectError("from a | enrich countries on foo with bar*", "Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]");
1058+
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [foo*]");
1059+
expectError("from a | enrich countries on * ", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
1060+
expectError(
1061+
"from a | enrich countries on foo with bar*",
1062+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1063+
);
1064+
expectError("from a | enrich countries on foo with *", "Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]");
10601065
expectError(
10611066
"from a | enrich countries on foo with x = bar* ",
1062-
"Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]"
1067+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [bar*]"
1068+
);
1069+
expectError(
1070+
"from a | enrich countries on foo with x = * ",
1071+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10631072
);
10641073
expectError(
10651074
"from a | enrich countries on foo with x* = bar ",
1066-
"Using wildcards [*] in ENRICH WITH projections is not allowed [x*]"
1075+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [x*]"
1076+
);
1077+
expectError(
1078+
"from a | enrich countries on foo with * = bar ",
1079+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [*]"
10671080
);
10681081
expectError(
10691082
"from a | enrich typo:countries on foo",
@@ -1961,7 +1974,7 @@ public void testParamInInvalidPosition() {
19611974
expectError(
19621975
"from idx1 | " + enrich,
19631976
List.of(paramAsPattern("f1", pattern), paramAsIdentifier("f2", "f.2"), paramAsIdentifier("f3", "f.3*")),
1964-
"Using wildcards [*] in ENRICH WITH projections is not allowed [" + pattern + "]"
1977+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [" + pattern + "]"
19651978
);
19661979
expectError(
19671980
"from idx1 | " + enrich,

0 commit comments

Comments
 (0)