Skip to content

Commit 52c31d5

Browse files
branch-3.0: [fix](nereids) EliminateGroupByConstant should replace agg's group by after removing constant group by keys #49473 (#50043)
Cherry-picked from #49473 Co-authored-by: feiniaofeiafei <[email protected]>
1 parent e450a7d commit 52c31d5

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateGroupByConstant.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.apache.doris.nereids.trees.plans.Plan;
2828
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
2929
import org.apache.doris.nereids.util.ExpressionUtils;
30+
import org.apache.doris.nereids.util.Utils;
3031

31-
import com.google.common.collect.ImmutableList;
3232
import com.google.common.collect.Sets;
3333

3434
import java.util.HashMap;
@@ -75,7 +75,8 @@ public Rule build() {
7575
if (slotGroupByExprs.isEmpty() && lit != null) {
7676
slotGroupByExprs.add(lit);
7777
}
78-
return aggregate.withGroupByAndOutput(ImmutableList.copyOf(slotGroupByExprs),
78+
return aggregate.withGroupByAndOutput(
79+
ExpressionUtils.replace(Utils.fastToImmutableList(slotGroupByExprs), constantExprsReplaceMap),
7980
ExpressionUtils.replaceNamedExpressions(outputExprs, constantExprsReplaceMap));
8081
}).toRule(RuleType.ELIMINATE_GROUP_BY_CONSTANT);
8182
}

regression-test/suites/nereids_p0/aggregate/aggregate_groupby_constant.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
suite("aggregate_groupby_constant") {
1919
sql "SET enable_nereids_planner=true"
2020
sql "SET enable_fallback_to_original_planner=false"
21+
sql "set disable_nereids_rules='prune_empty_partition'"
2122

2223
sql """ DROP TABLE IF EXISTS table_500_undef_partitions2_keys3_properties4_distributed_by5; """
2324
sql """
@@ -47,4 +48,29 @@ suite("aggregate_groupby_constant") {
4748
OR table1 . `col_int_undef_signed` <> NULL )
4849
GROUP BY field1,field2
4950
ORDER BY field1,field2 LIMIT 10000;"""
51+
52+
sql """
53+
SELECT
54+
IF(
55+
t.`col_varchar_10__undef_signed` IN ('女'),
56+
(
57+
TIMESTAMPDIFF(
58+
YEAR,
59+
NOW(),
60+
NOW()
61+
)
62+
),
63+
1
64+
) AS x0,
65+
TIMESTAMPDIFF(
66+
YEAR,
67+
NOW(),
68+
NOW()
69+
) AS x1
70+
FROM
71+
table_500_undef_partitions2_keys3_properties4_distributed_by5 AS t
72+
GROUP BY
73+
x0,
74+
x1;
75+
"""
5076
}

0 commit comments

Comments
 (0)