Skip to content

Commit

Permalink
[enhancement](nereids)optimized aggregate node's error msg (#38122)
Browse files Browse the repository at this point in the history
## 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.-->
  • Loading branch information
starocean999 authored and dataroaring committed Jul 24, 2024
1 parent 5b9e491 commit 0cc1908
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -622,10 +623,19 @@ private Plan bindAggregate(MatchingContext<LogicalAggregate<Plan>> ctx) {
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) {
Expand Down
15 changes: 15 additions & 0 deletions regression-test/suites/nereids_p0/aggregate/agg_error_msg.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

0 comments on commit 0cc1908

Please sign in to comment.