diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java index 2869097555b6aa..420bee53e18293 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java @@ -97,8 +97,12 @@ public static DateLiteral getRangeEnd(DateLiteral beginTime, FunctionIntervalInf switch (timeUnit) { case "year": return beginTime.plusYears(interval); + case "quarter": + return beginTime.plusMonths(interval * 3); case "month": return beginTime.plusMonths(interval); + case "week": + return beginTime.plusDays(interval * 7); case "day": return beginTime.plusDays(interval); case "hour": diff --git a/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy b/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy index 52325690ce7f61..e0f8db3ac8f7e7 100644 --- a/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy +++ b/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy @@ -20,9 +20,8 @@ suite("test_auto_range_partition") { sql """ CREATE TABLE `range_table1` ( `TIME_STAMP` datetimev2 NOT NULL COMMENT '采集日期' - ) ENGINE=OLAP + ) DUPLICATE KEY(`TIME_STAMP`) - COMMENT 'OLAP' auto partition by range (date_trunc(`TIME_STAMP`, 'day')) ( ) @@ -102,4 +101,42 @@ suite("test_auto_range_partition") { result2 = sql "show partitions from right_bound" logger.info("${result2}") assertEquals(result2.size(), 2) + + sql "drop table if exists week_range" + sql """ + CREATE TABLE `week_range` ( + `TIME_STAMP` datev2 NOT NULL + ) + DUPLICATE KEY(`TIME_STAMP`) + auto partition by range (date_trunc(`TIME_STAMP`, 'week')) + ( + ) + DISTRIBUTED BY HASH(`TIME_STAMP`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql " insert into week_range values (20240408), (20240409); " + result2 = sql "show partitions from week_range" + logger.info("${result2}") + assertEquals(result2.size(), 1) + + sql "drop table if exists quarter_range" + sql """ + CREATE TABLE `quarter_range` ( + `TIME_STAMP` datev2 NOT NULL + ) + DUPLICATE KEY(`TIME_STAMP`) + auto partition by range (date_trunc(`TIME_STAMP`, 'quarter')) + ( + ) + DISTRIBUTED BY HASH(`TIME_STAMP`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql " insert into quarter_range values (20240102), (20240330), (20241001), (20241231); " + result2 = sql "show partitions from quarter_range" + logger.info("${result2}") + assertEquals(result2.size(), 2) }