From e697fa2a5cb216f9429ed727478e837cbb7f698b Mon Sep 17 00:00:00 2001 From: morrySnow Date: Tue, 18 Feb 2025 14:10:42 +0800 Subject: [PATCH] [opt](Nereids) support bind asterisk in aggregate --- .../nereids/rules/analysis/BindExpression.java | 18 +++++++++++++++--- .../nereids_syntax_p0/analyze_agg.groovy | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java index 4f94516cf263fb..44e507c76f0cda 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java @@ -669,10 +669,22 @@ private Plan bindAggregate(MatchingContext> ctx) { SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer( agg, cascadesContext, agg.children(), true, true); List boundAggOutput = aggOutputAnalyzer.analyzeToList(agg.getOutputExpressions()); - Supplier aggOutputScopeWithoutAggFun = buildAggOutputScopeWithoutAggFun(boundAggOutput, cascadesContext); + ImmutableList.Builder boundProjectionsBuilder = ImmutableList.builder(); + for (int i = 0; i < boundAggOutput.size(); i++) { + NamedExpression output = boundAggOutput.get(i); + if (output instanceof BoundStar) { + List slots = ((BoundStar) output).getSlots(); + boundProjectionsBuilder.addAll(slots); + } else { + boundProjectionsBuilder.add(output); + } + } + List boundProjections = boundProjectionsBuilder.build(); + Supplier aggOutputScopeWithoutAggFun = buildAggOutputScopeWithoutAggFun( + boundProjections, cascadesContext); List boundGroupBy = bindGroupBy( - agg, agg.getGroupByExpressions(), boundAggOutput, aggOutputScopeWithoutAggFun, cascadesContext); - return agg.withGroupByAndOutput(boundGroupBy, boundAggOutput); + agg, agg.getGroupByExpressions(), boundProjections, aggOutputScopeWithoutAggFun, cascadesContext); + return agg.withGroupByAndOutput(boundGroupBy, boundProjections); } private Plan bindRepeat(MatchingContext> ctx) { diff --git a/regression-test/suites/nereids_syntax_p0/analyze_agg.groovy b/regression-test/suites/nereids_syntax_p0/analyze_agg.groovy index 9a79df6bad524b..af474c1ec76998 100644 --- a/regression-test/suites/nereids_syntax_p0/analyze_agg.groovy +++ b/regression-test/suites/nereids_syntax_p0/analyze_agg.groovy @@ -88,4 +88,6 @@ suite("analyze_agg") { 1, x """ + + sql """select * from (select id from t2) t group by id""" } \ No newline at end of file