Skip to content

Commit 896c378

Browse files
committed
Add parsing tests that inspect the whole AST
1 parent 355ce70 commit 896c378

File tree

6 files changed

+427
-68
lines changed

6 files changed

+427
-68
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Expressions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public static AttributeSet references(List<? extends Expression> exps) {
105105
}
106106

107107
public static String name(Expression e) {
108-
return e instanceof NamedExpression ne ? ne.name() : e.sourceText();
108+
return e instanceof Attribute attr && attr.qualifier() != null ? attr.qualifiedName()
109+
: e instanceof NamedExpression ne ? ne.name()
110+
: e.sourceText();
109111
}
110112

111113
/**

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/UnresolvedAttribute.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public UnresolvedAttribute(
6868
) {
6969
super(source, qualifier, name, id);
7070
this.customMessage = unresolvedMessage != null;
71-
this.unresolvedMsg = unresolvedMessage == null ? errorMessage(name(), null) : unresolvedMessage;
71+
this.unresolvedMsg = unresolvedMessage == null
72+
? errorMessage(qualifier() != null ? qualifiedName() : name(), null)
73+
: unresolvedMessage;
7274
this.resolutionMetadata = resolutionMetadata;
7375
}
7476

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
@@ -941,7 +941,7 @@ private Alias visitRerankField(EsqlBaseParser.RerankFieldContext ctx, Source sou
941941

942942
var boolExprCtx = ctx.booleanExpression();
943943
Expression value = boolExprCtx == null ? id : expression(boolExprCtx);
944-
return new Alias(source, id.name(), value);
944+
return new Alias(source, source(ctx.qualifiedName()).text(), value);
945945
}
946946

947947
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public PlanFactory visitDissectCommand(EsqlBaseParser.DissectCommandContext ctx)
257257
public PlanFactory visitMvExpandCommand(EsqlBaseParser.MvExpandCommandContext ctx) {
258258
UnresolvedAttribute field = visitQualifiedName(ctx.qualifiedName());
259259
Source src = source(ctx);
260-
return child -> new MvExpand(src, child, field, new UnresolvedAttribute(src, field.name()));
260+
return child -> new MvExpand(src, child, field, new UnresolvedAttribute(src, field.qualifier(), field.name(), null));
261261

262262
}
263263

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ public void testAggsExpressionsInStatsAggs() {
388388
"1:19: grouping key [e] already specified in the STATS BY clause",
389389
error("from test | stats e BY e = languages + emp_no")
390390
);
391+
assertEquals(
392+
"1:19: grouping key [[q].[e]] already specified in the STATS BY clause",
393+
error("from test | stats [q].[e] BY [q].[e]")
394+
);
395+
assertEquals(
396+
"1:19: Cannot specify grouping expression [[q].[e]] as an aggregate",
397+
error("from test | stats [q].[e] BY x = [q].[e]")
398+
);
391399

392400
var message = error("from test | stats languages + emp_no BY e = languages + emp_no");
393401
assertThat(

0 commit comments

Comments
 (0)