From a4151e022e3f7976c5e6aab4a309f2b49ad0a7ad Mon Sep 17 00:00:00 2001 From: zhangstar333 <87313068+zhangstar333@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:39:24 +0800 Subject: [PATCH] [bug](fold) fix fold constant rule can't handle variable expr (#32313) --- .../doris/rewrite/FoldConstantsRule.java | 3 +- .../suites/delete_p0/test_delete.groovy | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java index 62d74b429a..3ef20a5651 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java @@ -100,7 +100,8 @@ public class FoldConstantsRule implements ExprRewriteRule { // children should have been folded at this point. for (Expr child : expr.getChildren()) { if (!child.isLiteral() && !(child instanceof CastExpr) && !((child instanceof FunctionCallExpr - || child instanceof ArithmeticExpr || child instanceof TimestampArithmeticExpr))) { + || child instanceof ArithmeticExpr || child instanceof TimestampArithmeticExpr + || child instanceof VariableExpr))) { return expr; } } diff --git a/regression-test/suites/delete_p0/test_delete.groovy b/regression-test/suites/delete_p0/test_delete.groovy index ac428cb5dc..bdb1cf8e89 100644 --- a/regression-test/suites/delete_p0/test_delete.groovy +++ b/regression-test/suites/delete_p0/test_delete.groovy @@ -446,4 +446,41 @@ suite("test_delete") { """ sql "set experimental_enable_nereids_planner = false;" sql "delete from test3 where statistic_date >= date_sub('2024-01-16',INTERVAL 1 day);" + + sql "drop table if exists bi_acti_per_period_plan" + sql """ + CREATE TABLE `bi_acti_per_period_plan` ( + `proj_id` bigint(20) NULL, + `proj_name` varchar(400) NULL, + `proj_start_date` datetime NULL, + `proj_end_date` datetime NULL, + `last_data_date` datetime NULL, + `data_date` datetime NULL, + `data_batch_num` datetime NULL, + `la_sum_base_proj_id` varchar(200) NULL, + `sum_base_proj_id` varchar(200) NULL, + `today_date` datetime NULL, + `count` bigint(20) NULL, + `count_type` varchar(50) NULL, + `bl_count` bigint(20) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`proj_id`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`proj_id`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); + """ + sql """ + INSERT INTO bi_acti_per_period_plan (proj_id,proj_name,proj_start_date,proj_end_date,last_data_date,data_date,data_batch_num,la_sum_base_proj_id,sum_base_proj_id,today_date,count,count_type,bl_count) VALUES + (4508,'建筑工程项目A','2023-05-30 00:00:00','2024-03-07 00:00:00','2023-06-01 00:00:00','2023-08-15 00:00:00','2024-01-31 00:00:00','4509','4509','2023-08-27 00:00:00',5,'plan',4); + """ + sql "set experimental_enable_nereids_planner = false;" + sql "set @data_batch_num='2024-01-31 00:00:00';" + sql "delete from bi_acti_per_period_plan where data_batch_num =@data_batch_num; " }