diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateGroupByConstant.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateGroupByConstant.java index 7f7e229da319f4..a58d98ff1217bd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateGroupByConstant.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateGroupByConstant.java @@ -27,8 +27,8 @@ import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; import org.apache.doris.nereids.util.ExpressionUtils; +import org.apache.doris.nereids.util.Utils; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import java.util.HashMap; @@ -75,7 +75,8 @@ public Rule build() { if (slotGroupByExprs.isEmpty() && lit != null) { slotGroupByExprs.add(lit); } - return aggregate.withGroupByAndOutput(ImmutableList.copyOf(slotGroupByExprs), + return aggregate.withGroupByAndOutput( + ExpressionUtils.replace(Utils.fastToImmutableList(slotGroupByExprs), constantExprsReplaceMap), ExpressionUtils.replaceNamedExpressions(outputExprs, constantExprsReplaceMap)); }).toRule(RuleType.ELIMINATE_GROUP_BY_CONSTANT); } diff --git a/regression-test/suites/nereids_p0/aggregate/aggregate_groupby_constant.groovy b/regression-test/suites/nereids_p0/aggregate/aggregate_groupby_constant.groovy index ffd6c9b382e2e3..f65f7e6f633c80 100644 --- a/regression-test/suites/nereids_p0/aggregate/aggregate_groupby_constant.groovy +++ b/regression-test/suites/nereids_p0/aggregate/aggregate_groupby_constant.groovy @@ -18,6 +18,7 @@ suite("aggregate_groupby_constant") { sql "SET enable_nereids_planner=true" sql "SET enable_fallback_to_original_planner=false" + sql "set disable_nereids_rules='prune_empty_partition'" sql """ DROP TABLE IF EXISTS table_500_undef_partitions2_keys3_properties4_distributed_by5; """ sql """ @@ -47,4 +48,29 @@ suite("aggregate_groupby_constant") { OR table1 . `col_int_undef_signed` <> NULL ) GROUP BY field1,field2 ORDER BY field1,field2 LIMIT 10000;""" + + sql """ + SELECT + IF( + t.`col_varchar_10__undef_signed` IN ('女'), + ( + TIMESTAMPDIFF( + YEAR, + NOW(), + NOW() + ) + ), + 1 + ) AS x0, + TIMESTAMPDIFF( + YEAR, + NOW(), + NOW() + ) AS x1 + FROM + table_500_undef_partitions2_keys3_properties4_distributed_by5 AS t + GROUP BY + x0, + x1; + """ }