Skip to content

Commit

Permalink
branch-3.0: [fix](nereids)EliminateGroupBy rule should keep output's …
Browse files Browse the repository at this point in the history
…datatype unchanged #45359 (#45398)

Cherry-picked from #45359

Co-authored-by: starocean999 <[email protected]>
  • Loading branch information
github-actions[bot] and starocean999 authored Dec 16, 2024
1 parent e83b6a7 commit 1ba9b85
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.doris.nereids.trees.expressions.functions.agg.Min;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.PlanUtils;
Expand Down Expand Up @@ -84,12 +84,8 @@ public Rule build() {
.castIfNotSameType(f.child(0), f.getDataType()), ne.getName()));
} else if (f instanceof Count) {
newOutput.add((NamedExpression) ne.withChildren(
new If(
new IsNull(f.child(0)),
Literal.of(0),
Literal.of(1)
)
));
new If(new IsNull(f.child(0)), new BigIntLiteral(0),
new BigIntLiteral(1))));
} else {
throw new IllegalStateException("Unexpected aggregate function: " + f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void eliminateCount() {
logicalEmptyRelation().when(p -> p.getProjects().get(0).toSql().equals("id")
&& p.getProjects().get(1).toSql()
.equals("if(age IS NULL, 0, 1) AS `if(age IS NULL, 0, 1)`")
&& p.getProjects().get(1).getDataType().isBigIntType()
)
);
}
Expand Down

0 comments on commit 1ba9b85

Please sign in to comment.