From e25114e2142639864285dd1192fad3be74f41de5 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 11 Jul 2024 18:53:50 +0800 Subject: [PATCH 1/5] 1 --- .../org/apache/doris/mtmv/MTMVPartitionExprDateTrunc.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionExprDateTrunc.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionExprDateTrunc.java index a42fae22585873..f16252cede0a10 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionExprDateTrunc.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionExprDateTrunc.java @@ -47,7 +47,7 @@ import java.util.Set; public class MTMVPartitionExprDateTrunc implements MTMVPartitionExprService { - private static Set timeUnits = ImmutableSet.of("year", "month", "day"); + private static Set timeUnits = ImmutableSet.of("year", "month", "day", "hour"); private String timeUnit; public MTMVPartitionExprDateTrunc(FunctionCallExpr functionCallExpr) throws AnalysisException { @@ -202,6 +202,9 @@ private DateTimeV2Literal dateIncrement(DateTimeV2Literal value) throws Analysis case "day": result = value.plusDays(1L); break; + case "hour": + result = value.plusHours(1L); + break; default: throw new AnalysisException( "async materialized view partition roll up not support timeUnit: " + timeUnit); From f76cc5812c3df8b745307cbb83998fd5059f403b Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 11 Jul 2024 19:04:24 +0800 Subject: [PATCH 2/5] 1 --- .../mtmv_p0/test_rollup_partition_mtmv.groovy | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy index c24bc5aa91085a..47f35752e2f087 100644 --- a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy @@ -661,7 +661,7 @@ suite("test_rollup_partition_mtmv") { log.info(e.getMessage()) } - // not support trunc hour + // not support trunc minute sql """drop table if exists `${tableName}`""" sql """drop materialized view if exists ${mvName};""" sql """ @@ -673,9 +673,9 @@ suite("test_rollup_partition_mtmv") { COMMENT 'OLAP' PARTITION BY range(`k2`) ( - PARTITION p_20200101 VALUES [("2020-01-01"),("2020-01-02")), - PARTITION p_20200102 VALUES [("2020-01-02"),("2020-01-03")), - PARTITION p_20200201 VALUES [("2020-02-01"),("2020-02-02")) + PARTITION p_1 VALUES [("2020-01-01 00:00:00"),("2020-01-01 00:30:00")), + PARTITION p_2 VALUES [("2020-01-01 00:30:00"),("2020-01-01 01:00:00")), + PARTITION p_3 VALUES [("2020-01-01 01:00:00"),("2020-01-01 01:30:00")) ) DISTRIBUTED BY HASH(`k1`) BUCKETS 2 PROPERTIES ('replication_num' = '1') ; @@ -685,7 +685,7 @@ suite("test_rollup_partition_mtmv") { sql """ CREATE MATERIALIZED VIEW ${mvName} BUILD DEFERRED REFRESH AUTO ON MANUAL - partition by (date_trunc(`k2`,'hour')) + partition by (date_trunc(`k2`,'minute')) DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ( 'replication_num' = '1' @@ -698,6 +698,23 @@ suite("test_rollup_partition_mtmv") { log.info(e.getMessage()) } + // support hour + sql """ + CREATE MATERIALIZED VIEW ${mvName} + BUILD DEFERRED REFRESH AUTO ON MANUAL + partition by (date_trunc(`k2`,'minute')) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * FROM ${tableName}; + """ + + def hour_partitions = sql """show partitions from ${mvName}""" + logger.info("hour_partitions: " + hour_partitions.toString()) + assertEquals(2, hour_partitions.size()) + sql """drop materialized view if exists ${mvName};""" try { sql """ From 0aa15267568806f20e064f98a7dea503f4260bf9 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 11 Jul 2024 19:07:57 +0800 Subject: [PATCH 3/5] 1 --- .../suites/mtmv_p0/test_rollup_partition_mtmv.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy index 47f35752e2f087..3eae0a145700ce 100644 --- a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy @@ -667,7 +667,7 @@ suite("test_rollup_partition_mtmv") { sql """ CREATE TABLE `${tableName}` ( `k1` LARGEINT NOT NULL COMMENT '\"用户id\"', - `k2` DATE NOT NULL COMMENT '\"数据灌入日期时间\"' + `k2` DATETIME NOT NULL COMMENT '\"数据灌入日期时间\"' ) ENGINE=OLAP DUPLICATE KEY(`k1`) COMMENT 'OLAP' From 029bd3976c9053d1ccc3d320ef4aebde4b0ec9c1 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 11 Jul 2024 19:10:27 +0800 Subject: [PATCH 4/5] 1 --- .../suites/mtmv_p0/test_rollup_partition_mtmv.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy index 3eae0a145700ce..c2145eafd43408 100644 --- a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy @@ -702,7 +702,7 @@ suite("test_rollup_partition_mtmv") { sql """ CREATE MATERIALIZED VIEW ${mvName} BUILD DEFERRED REFRESH AUTO ON MANUAL - partition by (date_trunc(`k2`,'minute')) + partition by (date_trunc(`k2`,'hour')) DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ( 'replication_num' = '1' From f7e8eca3a699a8bc7ec81a5c16e13cbbcc2b508f Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 11 Jul 2024 19:17:07 +0800 Subject: [PATCH 5/5] 1 --- .../suites/mtmv_p0/test_rollup_partition_mtmv.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy index c2145eafd43408..21c77bc1e2473d 100644 --- a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy @@ -720,18 +720,18 @@ suite("test_rollup_partition_mtmv") { sql """ CREATE MATERIALIZED VIEW ${mvName} BUILD DEFERRED REFRESH AUTO ON MANUAL - partition by (hour_alias) + partition by (minute_alias) DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ( 'replication_num' = '1' ) AS - SELECT date_trunc(`k2`,'hour') as hour_alias, * FROM ${tableName}; + SELECT date_trunc(`k2`,'minute') as minute_alias, * FROM ${tableName}; """ Assert.fail(); } catch (Exception e) { log.info(e.getMessage()) - assertTrue(e.getMessage().contains("timeUnit not support: hour")) + assertTrue(e.getMessage().contains("timeUnit not support: minute")) } sql """drop materialized view if exists ${mvName};""" @@ -739,7 +739,7 @@ suite("test_rollup_partition_mtmv") { sql """ CREATE MATERIALIZED VIEW ${mvName} BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by (date_trunc(minute_alias, 'hour')) + partition by (date_trunc(minute_alias, 'minute')) DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ( 'replication_num' = '1' @@ -750,6 +750,6 @@ suite("test_rollup_partition_mtmv") { Assert.fail(); } catch (Exception e) { log.info(e.getMessage()) - assertTrue(e.getMessage().contains("timeUnit not support: hour")) + assertTrue(e.getMessage().contains("timeUnit not support: minute")) } }