Skip to content

Commit

Permalink
[branch-2.1](auto-partition) fix auto partition expr change unexpected (
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb authored Jun 20, 2024
1 parent cbaff8a commit 6df1a9a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ public boolean enableAutomaticPartition() {
return isAutoCreatePartitions;
}

// forbid change metadata.
public ArrayList<Expr> getPartitionExprs() {
return this.partitionExprs;
return Expr.cloneList(this.partitionExprs);
}

public void checkPartitionItemListsMatch(List<PartitionItem> list1, List<PartitionItem> list2) throws DdlException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}

0 comments on commit 6df1a9a

Please sign in to comment.