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 8a74d71917c15b..15f8dabc8f7da4 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 @@ -110,6 +110,7 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -622,10 +623,19 @@ 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); + List boundProjections = new ArrayList<>(boundAggOutput.size()); + for (NamedExpression output : boundAggOutput) { + if (output instanceof BoundStar) { + boundProjections.addAll(((BoundStar) output).getSlots()); + } else { + boundProjections.add(output); + } + } + 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_p0/aggregate/agg_error_msg.groovy b/regression-test/suites/nereids_p0/aggregate/agg_error_msg.groovy index 0b807be9d3add2..a644a26ade7330 100644 --- a/regression-test/suites/nereids_p0/aggregate/agg_error_msg.groovy +++ b/regression-test/suites/nereids_p0/aggregate/agg_error_msg.groovy @@ -47,4 +47,19 @@ suite("agg_error_msg") { sql """SELECT col_int_undef_signed2 col_alias1, col_int_undef_signed * (SELECT MAX (col_int_undef_signed) FROM table_20_undef_partitions2_keys3_properties4_distributed_by58 where table_20_undef_partitions2_keys3_properties4_distributed_by53.pk = pk) AS col_alias2 FROM table_20_undef_partitions2_keys3_properties4_distributed_by53 GROUP BY GROUPING SETS ((col_int_undef_signed2),()) ;""" exception "pk, col_int_undef_signed not in aggregate's output"; } + + test { + sql """SELECT * from table_20_undef_partitions2_keys3_properties4_distributed_by58 group by 1;""" + exception "col_int_undef_signed, col_int_undef_signed2 not in aggregate's output"; + } + + test { + sql """SELECT *, pk from table_20_undef_partitions2_keys3_properties4_distributed_by58 group by 1;""" + exception "col_int_undef_signed, col_int_undef_signed2 not in aggregate's output"; + } + + test { + sql """SELECT *, * from table_20_undef_partitions2_keys3_properties4_distributed_by58 group by 1;""" + exception "col_int_undef_signed, col_int_undef_signed2 not in aggregate's output"; + } }