This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new ae8073f1556 [opt](mtmv) partition rollup support week and quarter 
(#39286) (#39477)
ae8073f1556 is described below

commit ae8073f1556edc573961a72b4aae55c6578d4b34
Author: zhangdong <[email protected]>
AuthorDate: Fri Aug 16 20:01:06 2024 +0800

    [opt](mtmv) partition rollup support week and quarter (#39286) (#39477)
    
    pick from master #39286​
---
 .../doris/mtmv/MTMVPartitionExprDateTrunc.java     |  8 +-
 .../data/mtmv_p0/test_rollup_partition_mtmv.out    | 10 +++
 .../mtmv_p0/test_rollup_partition_mtmv.groovy      | 96 ++++++++++++++++++++++
 3 files changed, 113 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 0fcfaa909e6..ea15c84d1b9 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.Optional;
 import java.util.Set;
 
 public class MTMVPartitionExprDateTrunc implements MTMVPartitionExprService {
-    private static Set<String> timeUnits = ImmutableSet.of("year", "month", 
"day", "hour");
+    private static Set<String> timeUnits = ImmutableSet.of("year", "quarter", 
"week", "month", "day", "hour");
     private String timeUnit;
 
     public MTMVPartitionExprDateTrunc(FunctionCallExpr functionCallExpr) 
throws AnalysisException {
@@ -198,9 +198,15 @@ public class MTMVPartitionExprDateTrunc implements 
MTMVPartitionExprService {
             case "year":
                 result = value.plusYears(1L);
                 break;
+            case "quarter":
+                result = value.plusMonths(3L);
+                break;
             case "month":
                 result = value.plusMonths(1L);
                 break;
+            case "week":
+                result = value.plusWeeks(1L);
+                break;
             case "day":
                 result = value.plusDays(1L);
                 break;
diff --git a/regression-test/data/mtmv_p0/test_rollup_partition_mtmv.out 
b/regression-test/data/mtmv_p0/test_rollup_partition_mtmv.out
index f828e65cc70..a41a4087c0a 100644
--- a/regression-test/data/mtmv_p0/test_rollup_partition_mtmv.out
+++ b/regression-test/data/mtmv_p0/test_rollup_partition_mtmv.out
@@ -1,4 +1,14 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !date_range_quarter --
+1      2020-01-01      2020-01-01
+2      2020-04-01      2020-04-01
+3      2020-02-01      2020-02-01
+
+-- !date_range_week --
+1      2020-01-01      2020-01-01
+2      2020-01-02      2020-01-02
+3      2020-01-08      2020-01-08
+
 -- !date_range_month --
 1      2020-01-01      2020-01-01
 2      2020-01-02      2020-01-02
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 514c784534c..a9eeacc1c89 100644
--- a/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy
+++ b/regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy
@@ -61,6 +61,102 @@ suite("test_rollup_partition_mtmv") {
           exception "only support"
       }
 
+    // quarter
+    sql """drop table if exists `${tableName}`"""
+    sql """drop materialized view if exists ${mvName};"""
+    sql """
+        CREATE TABLE `${tableName}` (
+          `k1` LARGEINT NOT NULL COMMENT '\"用户id\"',
+          `k2` DATE NOT NULL COMMENT '\"数据灌入日期时间\"',
+          `k3` DATE NOT NULL COMMENT '\"日期时间\"'
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`k1`)
+        COMMENT 'OLAP'
+        PARTITION BY range(`k2`)
+        (
+        PARTITION p_20200101 VALUES [("2020-01-01"),("2020-01-02")),
+        PARTITION p_20200401 VALUES [("2020-04-01"),("2020-04-02")),
+        PARTITION p_20200201 VALUES [("2020-02-01"),("2020-02-02"))
+        )
+        DISTRIBUTED BY HASH(`k1`) BUCKETS 2
+        PROPERTIES ('replication_num' = '1') ;
+        """
+    sql """
+        insert into ${tableName} values(1,"2020-01-01", 
"2020-01-01"),(2,"2020-04-01", "2020-04-01"),(3,"2020-02-01", "2020-02-01");
+        """
+
+    sql """
+        CREATE MATERIALIZED VIEW ${mvName}
+            BUILD DEFERRED REFRESH AUTO ON MANUAL
+            partition by (date_trunc(`k2`,'quarter'))
+            DISTRIBUTED BY RANDOM BUCKETS 2
+            PROPERTIES (
+            'replication_num' = '1'
+            )
+            AS
+            SELECT * FROM ${tableName};
+    """
+    showPartitionsResult = sql """show partitions from ${mvName}"""
+    logger.info("showPartitionsResult: " + showPartitionsResult.toString())
+    assertEquals(2, showPartitionsResult.size())
+    assertTrue(showPartitionsResult.toString().contains("2020-01-01"))
+    assertTrue(showPartitionsResult.toString().contains("2020-04-01"))
+    assertTrue(showPartitionsResult.toString().contains("2020-07-01"))
+
+    sql """
+            REFRESH MATERIALIZED VIEW ${mvName} AUTO
+        """
+    waitingMTMVTaskFinishedByMvName(mvName)
+    order_qt_date_range_quarter "SELECT * FROM ${mvName} order by k1,k2"
+
+    // week
+    sql """drop table if exists `${tableName}`"""
+    sql """drop materialized view if exists ${mvName};"""
+    sql """
+        CREATE TABLE `${tableName}` (
+          `k1` LARGEINT NOT NULL COMMENT '\"用户id\"',
+          `k2` DATE NOT NULL COMMENT '\"数据灌入日期时间\"',
+          `k3` DATE NOT NULL COMMENT '\"日期时间\"'
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`k1`)
+        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_20200108 VALUES [("2020-01-08"),("2020-01-09"))
+        )
+        DISTRIBUTED BY HASH(`k1`) BUCKETS 2
+        PROPERTIES ('replication_num' = '1') ;
+        """
+    sql """
+        insert into ${tableName} values(1,"2020-01-01", 
"2020-01-01"),(2,"2020-01-02", "2020-01-02"),(3,"2020-01-08", "2020-01-08");
+        """
+
+    sql """
+        CREATE MATERIALIZED VIEW ${mvName}
+            BUILD DEFERRED REFRESH AUTO ON MANUAL
+            partition by (date_trunc(`k2`,'week'))
+            DISTRIBUTED BY RANDOM BUCKETS 2
+            PROPERTIES (
+            'replication_num' = '1'
+            )
+            AS
+            SELECT * FROM ${tableName};
+    """
+    showPartitionsResult = sql """show partitions from ${mvName}"""
+    logger.info("showPartitionsResult: " + showPartitionsResult.toString())
+    assertEquals(2, showPartitionsResult.size())
+    assertTrue(showPartitionsResult.toString().contains("2019-12-30"))
+    assertTrue(showPartitionsResult.toString().contains("2020-01-06"))
+    assertTrue(showPartitionsResult.toString().contains("2020-01-13"))
+
+    sql """
+            REFRESH MATERIALIZED VIEW ${mvName} AUTO
+        """
+    waitingMTMVTaskFinishedByMvName(mvName)
+    order_qt_date_range_week "SELECT * FROM ${mvName} order by k1,k2"
+
     // range date month
     sql """drop table if exists `${tableName}`"""
     sql """drop materialized view if exists ${mvName};"""


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to