Skip to content

Commit fc2c674

Browse files
Better error message
1 parent cf3c7e4 commit fc2c674

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ private NamedExpression enrichFieldName(EsqlBaseParser.QualifiedNamePatternConte
797797
return visitQualifiedNamePattern(ctx, ne -> {
798798
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 [{}]", src.text());
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,20 +1081,29 @@ 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 * ", "Using wildcards [*] in ENRICH WITH projections is not allowed [*]");
1086-
expectError("from a | enrich countries on foo with bar*", "Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]");
1087-
expectError("from a | enrich countries on foo with *", "Using wildcards [*] in ENRICH WITH projections is not allowed [*]");
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 [*]");
10881091
expectError(
10891092
"from a | enrich countries on foo with x = bar* ",
1090-
"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 [*]"
10911098
);
1092-
expectError("from a | enrich countries on foo with x = * ", "Using wildcards [*] in ENRICH WITH projections is not allowed [*]");
10931099
expectError(
10941100
"from a | enrich countries on foo with x* = bar ",
1095-
"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 [*]"
10961106
);
1097-
expectError("from a | enrich countries on foo with * = bar ", "Using wildcards [*] in ENRICH WITH projections is not allowed [*]");
10981107
expectError(
10991108
"from a | enrich typo:countries on foo",
11001109
"line 1:17: Unrecognized value [typo], ENRICH policy qualifier needs to be one of [_ANY, _COORDINATOR, _REMOTE]"
@@ -1977,7 +1986,7 @@ public void testParamInInvalidPosition() {
19771986
expectError(
19781987
"from idx1 | " + enrich,
19791988
List.of(paramAsPattern("f1", pattern), paramAsIdentifier("f2", "f.2"), paramAsIdentifier("f3", "f.3*")),
1980-
"Using wildcards [*] in ENRICH WITH projections is not allowed [" + pattern + "]"
1989+
"Using wildcards [*] in ENRICH WITH projections is not allowed, found [" + pattern + "]"
19811990
);
19821991
expectError(
19831992
"from idx1 | " + enrich,

0 commit comments

Comments
 (0)