|
20 | 20 | import org.elasticsearch.xpack.esql.analysis.AnalyzerRules.ParameterizedAnalyzerRule; |
21 | 21 | import org.elasticsearch.xpack.esql.common.Failure; |
22 | 22 | import org.elasticsearch.xpack.esql.core.capabilities.Resolvables; |
23 | | -import org.elasticsearch.xpack.esql.core.capabilities.Unresolvable; |
24 | 23 | import org.elasticsearch.xpack.esql.core.expression.Alias; |
25 | 24 | import org.elasticsearch.xpack.esql.core.expression.Attribute; |
26 | 25 | import org.elasticsearch.xpack.esql.core.expression.EmptyAttribute; |
@@ -592,32 +591,23 @@ private Aggregate resolveAggregate(Aggregate aggregate, List<Attribute> children |
592 | 591 | boolean groupingResolved = Resolvables.resolved(groupings); |
593 | 592 | int size = groupingResolved ? aggregates.size() : aggregates.size() - groupings.size(); |
594 | 593 | 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 -> { |
598 | 597 | Expression ne = ua; |
599 | 598 | 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; |
614 | 606 | } |
615 | 607 | return ne; |
616 | 608 | }); |
617 | | - newAggregates.add(agg); |
618 | | - } else { |
619 | | - newAggregates.add(ag); // Groupings are not resolved |
620 | 609 | } |
| 610 | + newAggregates.add(agg); |
621 | 611 | } |
622 | 612 |
|
623 | 613 | // TODO: remove this when Stats interface is removed |
|
0 commit comments