From 6df1a9ab753e1680bb2f001c2ee6a1df01749ca9 Mon Sep 17 00:00:00 2001 From: zclllyybb Date: Thu, 20 Jun 2024 17:50:31 +0800 Subject: [PATCH] [branch-2.1](auto-partition) fix auto partition expr change unexpected (#36345) (#36514) pick #36345 --- .../apache/doris/catalog/PartitionInfo.java | 3 +- .../analysis/PartitionPruneTestBase.java | 4 ++- .../analysis/RangePartitionPruneTest.java | 3 -- .../test_date_function_prune.groovy | 31 +++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java index c899a4e8917d50..434812b07d30be 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java @@ -249,8 +249,9 @@ public boolean enableAutomaticPartition() { return isAutoCreatePartitions; } + // forbid change metadata. public ArrayList getPartitionExprs() { - return this.partitionExprs; + return Expr.cloneList(this.partitionExprs); } public void checkPartitionItemListsMatch(List list1, List list2) throws DdlException { diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/PartitionPruneTestBase.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/PartitionPruneTestBase.java index 162a81ccb8812f..8a9d9787731394 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/PartitionPruneTestBase.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/PartitionPruneTestBase.java @@ -34,7 +34,9 @@ protected void doTest() throws Exception { } private void assertExplainContains(String sql, String subString) throws Exception { - Assert.assertTrue(String.format("sql=%s, expectResult=%s", sql, subString), + Assert.assertTrue( + String.format("sql=%s, expectResult=%s, but got %s", sql, subString, + getSQLPlanOrErrorMsg("explain " + sql)), getSQLPlanOrErrorMsg("explain " + sql).contains(subString)); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java index 4cd7f8d204937d..7bce2526df00c3 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java @@ -206,9 +206,6 @@ private void initTestCases() { "partitions=6/8"); addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test_to_date_trunc where event_day= \"2023-08-07 11:00:00\" ", "partitions=1/2"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test_to_date_trunc where date_trunc(event_day, \"day\")= \"2023-08-07 11:00:00\" ", - "partitions=1/2"); - } diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy index c126206eba0fb9..c6f122e3c8735b 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy @@ -91,4 +91,35 @@ suite("test_date_function_prune") { sql "select * from dp where date_time > str_to_date('2020-01-02','%Y-%m-%d')" contains("partitions=2/3 (p2,p3)") } + + sql "drop table if exists test_to_date_trunc" + sql """ + CREATE TABLE test_to_date_trunc( + event_day DATETIME NOT NULL + ) + DUPLICATE KEY(event_day) + AUTO PARTITION BY range (date_trunc(event_day, "day")) ( + PARTITION `p20230807` values [(20230807 ), (20230808 )), + PARTITION `p20020106` values [(20020106 ), (20020107 )) + ) + DISTRIBUTED BY HASH(event_day) BUCKETS 4 + PROPERTIES("replication_num" = "1"); + """ + explain { + sql """ select /*+ SET_VAR(enable_nereids_planner=false) */ * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ + contains("partitions=0/2") + } + explain { + sql """ select * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ + contains("VEMPTYSET") + } + sql """ insert into test_to_date_trunc values ("20230807000000"); """ + explain { + sql """ select /*+ SET_VAR(enable_nereids_planner=false) */ * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ + contains("partitions=1/2 (p20230807)") + } + explain { + sql """ select * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ + contains("partitions=1/2 (p20230807)") + } } \ No newline at end of file