This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit ae6ca5b9a9b40d0b73638b25f4007434a6650795 Author: HappenLee <[email protected]> AuthorDate: Fri Mar 24 20:22:12 2023 +0800 [Bug](delete) Fix bug of delete partition prune error (#18057) --- .../java/org/apache/doris/load/DeleteHandler.java | 19 ++++++--- regression-test/data/delete_p0/test_delete.out | 5 +++ .../suites/delete_p0/test_delete.groovy | 46 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java b/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java index 51db514127..aea4c3b324 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java @@ -179,7 +179,7 @@ public class DeleteHandler implements Writable { Set<String> partitionColumnNameSet = olapTable.getPartitionColumnNames(); Map<String, ColumnRange> columnNameToRange = Maps.newHashMap(); for (String colName : partitionColumnNameSet) { - ColumnRange columnRange = createColumnRange(colName, conditions); + ColumnRange columnRange = createColumnRange(olapTable, colName, conditions); // Not all partition columns are involved in predicate conditions if (columnRange != null) { columnNameToRange.put(colName, columnRange); @@ -411,11 +411,15 @@ public class DeleteHandler implements Writable { } // Return null if there is no filter for the partition column - private ColumnRange createColumnRange(String colName, List<Predicate> conditions) { + private ColumnRange createColumnRange(OlapTable table, String colName, List<Predicate> conditions) + throws AnalysisException { ColumnRange result = ColumnRange.create(); + Type type = + table.getBaseSchema().stream().filter(c -> c.getName().equals(colName)).findFirst().get().getType(); + boolean hasRange = false; for (Predicate predicate : conditions) { - List<Range<ColumnBound>> bounds = createColumnRange(colName, predicate); + List<Range<ColumnBound>> bounds = createColumnRange(colName, predicate, type); if (bounds != null) { hasRange = true; result.intersect(bounds); @@ -430,7 +434,8 @@ public class DeleteHandler implements Writable { // Return null if the condition is not related to the partition column, // or the operator is not supported. - private List<Range<ColumnBound>> createColumnRange(String colName, Predicate condition) { + private List<Range<ColumnBound>> createColumnRange(String colName, Predicate condition, Type type) + throws AnalysisException { List<Range<ColumnBound>> result = Lists.newLinkedList(); if (condition instanceof BinaryPredicate) { BinaryPredicate binaryPredicate = (BinaryPredicate) condition; @@ -441,7 +446,8 @@ public class DeleteHandler implements Writable { if (!colName.equalsIgnoreCase(columnName)) { return null; } - ColumnBound bound = ColumnBound.of((LiteralExpr) binaryPredicate.getChild(1)); + ColumnBound bound = ColumnBound.of( + LiteralExpr.create(((LiteralExpr) binaryPredicate.getChild(1)).getStringValue(), type)); switch (binaryPredicate.getOp()) { case EQ: result.add(Range.closed(bound, bound)); @@ -478,7 +484,8 @@ public class DeleteHandler implements Writable { return null; } for (int i = 1; i <= inPredicate.getInElementNum(); i++) { - ColumnBound bound = ColumnBound.of((LiteralExpr) inPredicate.getChild(i)); + ColumnBound bound = ColumnBound.of(LiteralExpr + .create(((LiteralExpr) inPredicate.getChild(i)).getStringValue(), type)); result.add(Range.closed(bound, bound)); } } else { diff --git a/regression-test/data/delete_p0/test_delete.out b/regression-test/data/delete_p0/test_delete.out index 37c01de74e..30765c79b8 100644 --- a/regression-test/data/delete_p0/test_delete.out +++ b/regression-test/data/delete_p0/test_delete.out @@ -40,3 +40,8 @@ abcdef 2022-08-16 2022-08-16T11:11:11 2022-08-16T11:11:11.111 2022-08-16 2022-08 -- !sql8 -- abcdef 2022-08-12 2022-08-16T12:11:11 2022-08-16T12:11:11.111 2022-08-12 2022-08-16T12:11:11 2022-08-16T12:11:11.111 +-- !sql9 -- +2022-10-01 123 + +-- !sql10 -- + diff --git a/regression-test/suites/delete_p0/test_delete.groovy b/regression-test/suites/delete_p0/test_delete.groovy index 90ecb6db02..e142ae7da5 100644 --- a/regression-test/suites/delete_p0/test_delete.groovy +++ b/regression-test/suites/delete_p0/test_delete.groovy @@ -72,4 +72,50 @@ suite("test_delete") { sql """ delete from delete_regression_test where k1 = 'abcdef' """ sql """ DROP TABLE IF EXISTS ${tableName} """ + + sql """ DROP TABLE IF EXISTS tb_test1 """ + sql """ CREATE TABLE `tb_test1` ( + `dt` date NULL, + `code` int(11) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`dt`, `code`) + COMMENT 'OLAP' + PARTITION BY RANGE(`dt`) + (PARTITION m202206 VALUES [('2022-06-01'), ('2022-07-01')), + PARTITION m202207 VALUES [('2022-07-01'), ('2022-08-01')), + PARTITION m202208 VALUES [('2022-08-01'), ('2022-09-01')), + PARTITION m202209 VALUES [('2022-09-01'), ('2022-10-01')), + PARTITION m202210 VALUES [('2022-10-01'), ('2022-11-01')), + PARTITION m202211 VALUES [('2022-11-01'), ('2022-12-01')), + PARTITION m202212 VALUES [('2022-12-01'), ('2023-01-01')), + PARTITION m202301 VALUES [('2023-01-01'), ('2023-02-01')), + PARTITION m202302 VALUES [('2023-02-01'), ('2023-03-01')), + PARTITION m202303 VALUES [('2023-03-01'), ('2023-04-01')), + PARTITION m202304 VALUES [('2023-04-01'), ('2023-05-01'))) + DISTRIBUTED BY HASH(`dt`, `code`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "dynamic_partition.enable" = "true", + "dynamic_partition.time_unit" = "MONTH", + "dynamic_partition.time_zone" = "Asia/Shanghai", + "dynamic_partition.start" = "-2147483648", + "dynamic_partition.end" = "1", + "dynamic_partition.prefix" = "m", + "dynamic_partition.replication_allocation" = "tag.location.default: 1", + "dynamic_partition.buckets" = "10", + "dynamic_partition.create_history_partition" = "false", + "dynamic_partition.history_partition_num" = "-1", + "dynamic_partition.hot_partition_num" = "0", + "dynamic_partition.reserved_history_periods" = "NULL", + "dynamic_partition.storage_policy" = "", + "dynamic_partition.start_day_of_month" = "1", + "in_memory" = "false", + "storage_format" = "V2", + "disable_auto_compaction" = "false" + ); + """ + sql """ insert into tb_test1 values ('2022-10-01', 123); """ + qt_sql9 """select * from tb_test1;""" + sql """ delete from tb_test1 where dt = '20221001'; """ + qt_sql10 """select * from tb_test1;""" } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
