Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ protected boolean condition(Rule rule, Plan plan) {
group_by_key is bound on t1.a
*/
duplicatedSlotNames.forEach(childOutputsToExpr::remove);
output.stream()
.filter(ne -> ne instanceof Alias)
.map(Alias.class::cast)
// agg function cannot be bound with group_by_key
.filter(alias -> !alias.child()
.anyMatch(expr -> expr instanceof AggregateFunction))
.forEach(alias -> childOutputsToExpr.putIfAbsent(alias.getName(), alias.child()));
for (int i = 0; i < output.size(); i++) {
if (!(output.get(i) instanceof Alias)) {
continue;
}
Alias alias = (Alias) output.get(i);
if (alias.child().anyMatch(expr -> expr instanceof AggregateFunction)) {
continue;
}
// NOTICE: must use unbound expressions, because we will bind them in binding group by expr.
childOutputsToExpr.putIfAbsent(alias.getName(), agg.getOutputExpressions().get(i).child(0));
}

List<Expression> replacedGroupBy = agg.getGroupByExpressions().stream()
.map(groupBy -> {
Expand Down
6 changes: 5 additions & 1 deletion regression-test/suites/nereids_syntax_p0/analyze_agg.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ suite("analyze_agg") {
d VARCHAR(30),
e VARCHAR(32),
a VARCHAR(32),
f VARCHAR(32)
f VARCHAR(32),
g DECIMAL(9, 3)
)ENGINE = OLAP
UNIQUE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 30
Expand Down Expand Up @@ -73,4 +74,7 @@ suite("analyze_agg") {
sql "select count(distinct t2.b), variance(distinct t2.c) from t2"
exception "variance(DISTINCT c#2) can't support multi distinct."
}

// should not bind g /g in group by again, otherwise will throw exception
sql "select g / g as nu, sum(c) from t2 group by nu"
}