This is an automated email from the ASF dual-hosted git repository. starocean999 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 33c878f313c [enhancement](nereids)optimized aggregate node's error msg (#38122) 33c878f313c is described below commit 33c878f313cec6633dc3dbd1e86753584f0a42ba Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Tue Jul 23 11:37:19 2024 +0800 [enhancement](nereids)optimized aggregate node's error msg (#38122) ## Proposed changes ``` create table t1 ( c1 bigint, c2 bigint ) DISTRIBUTED BY HASH(c1) BUCKETS 3 PROPERTIES ("replication_num" = "1"); ``` sql `select * from t1 group by 1;` the error msg before: ERROR 1105 (HY000): errCode = 2, detailMessage = Invalid call to toSlot on unbound object after: ERROR 1105 (HY000): errCode = 2, detailMessage = c2 not in aggregate's output Issue Number: close #xxx <!--Describe your changes.--> --- .../doris/nereids/rules/analysis/BindExpression.java | 16 +++++++++++++--- .../suites/nereids_p0/aggregate/agg_error_msg.groovy | 15 +++++++++++++++ 2 files changed, 28 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 8a74d71917c..15f8dabc8f7 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.LogManager; 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 @@ public class BindExpression implements AnalysisRuleFactory { SimpleExprAnalyzer aggOutputAnalyzer = buildSimpleExprAnalyzer( agg, cascadesContext, agg.children(), true, true); List<NamedExpression> boundAggOutput = aggOutputAnalyzer.analyzeToList(agg.getOutputExpressions()); - Supplier<Scope> aggOutputScopeWithoutAggFun = buildAggOutputScopeWithoutAggFun(boundAggOutput, cascadesContext); + List<NamedExpression> boundProjections = new ArrayList<>(boundAggOutput.size()); + for (NamedExpression output : boundAggOutput) { + if (output instanceof BoundStar) { + boundProjections.addAll(((BoundStar) output).getSlots()); + } else { + boundProjections.add(output); + } + } + Supplier<Scope> aggOutputScopeWithoutAggFun = + buildAggOutputScopeWithoutAggFun(boundProjections, cascadesContext); List<Expression> 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<LogicalRepeat<Plan>> 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 0b807be9d3a..a644a26ade7 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"; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org