Skip to content

Commit

Permalink
ESQL: Prepare analyzer for LOOKUP (elastic#109045)
Browse files Browse the repository at this point in the history
This extracts two fairly uncontroversial changes that were in the main
LOOKUP PR into a smaller change that's easier to review.
  • Loading branch information
nik9000 authored May 28, 2024
1 parent 3fad074 commit e5558ca
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,10 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
private static final Iterable<RuleExecutor.Batch<LogicalPlan>> rules;

static {
var resolution = new Batch<>(
"Resolution",
new ResolveTable(),
new ResolveEnrich(),
new ResolveFunctions(),
new ResolveRefs(),
new ImplicitCasting()
);
var init = new Batch<>("Initialize", Limiter.ONCE, new ResolveTable(), new ResolveEnrich(), new ResolveFunctions());
var resolution = new Batch<>("Resolution", new ResolveRefs(), new ImplicitCasting());
var finish = new Batch<>("Finish Analysis", Limiter.ONCE, new AddImplicitLimit());
rules = List.of(resolution, finish);
rules = List.of(init, resolution, finish);
}

private final Verifier verifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public Alias visitRenameClause(EsqlBaseParser.RenameClauseContext ctx) {
NamedExpression newName = visitQualifiedNamePattern(ctx.newName);
NamedExpression oldName = visitQualifiedNamePattern(ctx.oldName);
if (newName instanceof UnresolvedNamePattern || oldName instanceof UnresolvedNamePattern) {
throw new ParsingException(src, "Using wildcards (*) in RENAME is not allowed [{}]", src.text());
throw new ParsingException(src, "Using wildcards [*] in RENAME is not allowed [{}]", src.text());
}

return new Alias(src, newName.name(), oldName);
Expand All @@ -603,7 +603,7 @@ public NamedExpression visitEnrichWithClause(EsqlBaseParser.EnrichWithClauseCont
private NamedExpression enrichFieldName(EsqlBaseParser.QualifiedNamePatternContext ctx) {
var name = visitQualifiedNamePattern(ctx);
if (name instanceof UnresolvedNamePattern up) {
throw new ParsingException(source(ctx), "Using wildcards (*) in ENRICH WITH projections is not allowed [{}]", up.pattern());
throw new ParsingException(source(ctx), "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", up.pattern());
}
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public PlanFactory visitEnrichCommand(EsqlBaseParser.EnrichCommandContext ctx) {

NamedExpression matchField = ctx.ON() != null ? visitQualifiedNamePattern(ctx.matchField) : new EmptyAttribute(source);
if (matchField instanceof UnresolvedNamePattern up) {
throw new ParsingException(source, "Using wildcards (*) in ENRICH WITH projections is not allowed [{}]", up.pattern());
throw new ParsingException(source, "Using wildcards [*] in ENRICH WITH projections is not allowed [{}]", up.pattern());
}

List<NamedExpression> keepClauses = visitList(this, ctx.enrichWithClause(), NamedExpression.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public void testMultipleProjectPatterns() {
}

public void testForbidWildcardProjectRename() {
assertParsingException(() -> renameExpression("b* AS a*"), "line 1:18: Using wildcards (*) in RENAME is not allowed [b* AS a*]");
assertParsingException(() -> renameExpression("b* AS a*"), "line 1:18: Using wildcards [*] in RENAME is not allowed [b* AS a*]");
}

public void testSimplifyInWithSingleElementList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,15 @@ public void testEnrich() {
processingCommand("enrich _" + mode.name() + ":countries ON country_code")
);

expectError("from a | enrich countries on foo* ", "Using wildcards (*) in ENRICH WITH projections is not allowed [foo*]");
expectError("from a | enrich countries on foo with bar*", "Using wildcards (*) in ENRICH WITH projections is not allowed [bar*]");
expectError("from a | enrich countries on foo* ", "Using wildcards [*] in ENRICH WITH projections is not allowed [foo*]");
expectError("from a | enrich countries on foo with bar*", "Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]");
expectError(
"from a | enrich countries on foo with x = bar* ",
"Using wildcards (*) in ENRICH WITH projections is not allowed [bar*]"
"Using wildcards [*] in ENRICH WITH projections is not allowed [bar*]"
);
expectError(
"from a | enrich countries on foo with x* = bar ",
"Using wildcards (*) in ENRICH WITH projections is not allowed [x*]"
"Using wildcards [*] in ENRICH WITH projections is not allowed [x*]"
);
expectError(
"from a | enrich typo:countries on foo",
Expand Down

0 comments on commit e5558ca

Please sign in to comment.