Skip to content

Commit d57caf7

Browse files
refactor
1 parent 9f014a0 commit d57caf7

File tree

1 file changed

+11
-21
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis

1 file changed

+11
-21
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.elasticsearch.xpack.esql.analysis.AnalyzerRules.ParameterizedAnalyzerRule;
2121
import org.elasticsearch.xpack.esql.common.Failure;
2222
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
23-
import org.elasticsearch.xpack.esql.core.capabilities.Unresolvable;
2423
import org.elasticsearch.xpack.esql.core.expression.Alias;
2524
import org.elasticsearch.xpack.esql.core.expression.Attribute;
2625
import org.elasticsearch.xpack.esql.core.expression.EmptyAttribute;
@@ -592,32 +591,23 @@ private Aggregate resolveAggregate(Aggregate aggregate, List<Attribute> children
592591
boolean groupingResolved = Resolvables.resolved(groupings);
593592
int size = groupingResolved ? aggregates.size() : aggregates.size() - groupings.size();
594593
for (int i = 0; i < aggregates.size(); i++) {
595-
NamedExpression ag = aggregates.get(i);
596-
if (i < size) {
597-
var agg = (NamedExpression) ag.transformUp(UnresolvedAttribute.class, ua -> {
594+
NamedExpression agg = aggregates.get(i);
595+
if (i < size) { // Skip resolving references to groupings in the aggregations if the groupings are not resolved yet.
596+
agg = (NamedExpression) agg.transformUp(UnresolvedAttribute.class, ua -> {
598597
Expression ne = ua;
599598
Attribute maybeResolved = maybeResolveAttribute(ua, resolvedList);
600-
if (groupingResolved) {
601-
if (maybeResolved != null) {
602-
changed.set(true);
603-
ne = maybeResolved;
604-
}
605-
} else {
606-
// An item in aggregations can reference to groupings explicitly, if groupings are not resolved yet and
607-
// maybeResolved is not resolved, return the original UnresolvedAttribute, so that it has a another chance
608-
// to get resolved in the next iteration.
609-
// For example STATS c = count(emp_no), x = d::int + 1 BY d = (date == "2025-01-01")
610-
if (maybeResolved instanceof Unresolvable == false) {
611-
changed.set(true);
612-
ne = maybeResolved;
613-
}
599+
// An item in aggregations can reference to groupings explicitly, if groupings are not resolved yet and
600+
// maybeResolved is not resolved, return the original UnresolvedAttribute, so that it has another chance
601+
// to get resolved in the next iteration.
602+
// For example STATS c = count(emp_no), x = d::int + 1 BY d = (date == "2025-01-01")
603+
if (groupingResolved || maybeResolved.resolved()) {
604+
changed.set(true);
605+
ne = maybeResolved;
614606
}
615607
return ne;
616608
});
617-
newAggregates.add(agg);
618-
} else {
619-
newAggregates.add(ag); // Groupings are not resolved
620609
}
610+
newAggregates.add(agg);
621611
}
622612

623613
// TODO: remove this when Stats interface is removed

0 commit comments

Comments
 (0)