From 1ba9b85863fae3836ac0e0867466d1c6d58f5e7e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:58:33 +0800 Subject: [PATCH] branch-3.0: [fix](nereids)EliminateGroupBy rule should keep output's datatype unchanged #45359 (#45398) Cherry-picked from #45359 Co-authored-by: starocean999 --- .../doris/nereids/rules/rewrite/EliminateGroupBy.java | 10 +++------- .../nereids/rules/rewrite/EliminateGroupByTest.java | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupBy.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupBy.java index b50d3a41e8c3b5..9325607dd70769 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupBy.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupBy.java @@ -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; @@ -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); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByTest.java index 0b6d2f199fc59f..70eb8e4a470746 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByTest.java @@ -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() ) ); }