From 6d3b1ce5cbf537bb40fe55992599501cb99ce9ba Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Thu, 6 Jun 2024 11:35:09 +0800 Subject: [PATCH] [fix](nereids)should not push down constant output expr in window expression --- .../ExtractAndNormalizeWindowExpression.java | 3 ++- .../nereids_p0/aggregate/agg_window_project.groovy | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java index 6f067545cee0cc..c763bca49a5468 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java @@ -100,7 +100,8 @@ private Plan normalize(LogicalProject project) { // 1. handle bottom projects Set existedAlias = ExpressionUtils.collect(outputs, Alias.class::isInstance); - Set toBePushedDown = collectExpressionsToBePushedDown(outputs); + Set toBePushedDown = collectExpressionsToBePushedDown( + outputs.stream().filter(expr -> !expr.isConstant()).collect(Collectors.toList())); NormalizeToSlotContext context = NormalizeToSlotContext.buildContext(existedAlias, toBePushedDown); // set toBePushedDown exprs as NamedExpression, e.g. (a+1) -> Alias(a+1) Set bottomProjects = context.pushDownToNamedExpression(toBePushedDown); diff --git a/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy b/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy index eed0ec3fd24caa..df982c6d86ef1e 100644 --- a/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy +++ b/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy @@ -109,4 +109,18 @@ suite("agg_window_project") { sql """select a, a aa, row_number() over (partition by b) from test_window_table2;""" sql "DROP TABLE IF EXISTS test_window_table2;" + + sql """DROP TABLE IF EXISTS test_window_union_t1;""" + sql """DROP TABLE IF EXISTS test_window_union_t2;""" + sql """create table test_window_union_t1 (item_code int) distributed by hash(item_code) properties("replication_num"="1");""" + sql """insert into test_window_union_t1 values(1), (11), (111);""" + + sql """create table test_window_union_t2 (orderamount_lj_tq decimalv3(38,5)) distributed by hash(orderamount_lj_tq) properties("replication_num"="1");""" + sql """insert into test_window_union_t2 values(123456.12345), (223456.12345), (323456.12345);""" + + sql """ + SELECT 0 AS `amount_dh_real_tq`, (CASE WHEN `t`.`item_code` IS NOT NULL THEN (1.0 / count(1) OVER (PARTITION BY `t`.`item_code`)) ELSE 0.0 END) AS `item_qty_dh_order` FROM `test_window_union_t1` t + UNION ALL + SELECT `t`.`orderamount_lj_tq` AS `amount_dh_real_tq`, 0 AS `item_qty_dh_order` FROM `test_window_union_t2` t ; + """ }