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

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

commit 7ef4c1333050cc323c1df3e2cdafd4f2c093fb8c
Author: zhangdong <493738...@qq.com>
AuthorDate: Thu Aug 29 15:50:36 2024 +0800

    [fix](mtmv) Mtmv support set both immediate and starttime (#39573)
    
    extends: #36805
    
    Previously, if the user set immediate execution, the current time would
    replace the user's set start time
---
 .../java/org/apache/doris/mtmv/MTMVJobManager.java |  8 +--
 .../data/mtmv_p0/test_start_time_mtmv.out          | 17 +++++
 .../suites/mtmv_p0/test_start_time_mtmv.groovy     | 76 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java
index 11089899b30..1ace738f1d0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java
@@ -105,14 +105,14 @@ public class MTMVJobManager implements MTMVHookService {
                 
.setInterval(mtmv.getRefreshInfo().getRefreshTriggerInfo().getIntervalTrigger().getInterval());
         timerDefinition
                 
.setIntervalUnit(mtmv.getRefreshInfo().getRefreshTriggerInfo().getIntervalTrigger().getTimeUnit());
-        if (mtmv.getRefreshInfo().getBuildMode().equals(BuildMode.IMMEDIATE)) {
-            jobExecutionConfiguration.setImmediate(true);
-        } else if 
(mtmv.getRefreshInfo().getBuildMode().equals(BuildMode.DEFERRED) && !StringUtils
+        if (!StringUtils
                 
.isEmpty(mtmv.getRefreshInfo().getRefreshTriggerInfo().getIntervalTrigger().getStartTime()))
 {
             timerDefinition.setStartTimeMs(TimeUtils.timeStringToLong(
                     
mtmv.getRefreshInfo().getRefreshTriggerInfo().getIntervalTrigger().getStartTime()));
         }
-
+        if (mtmv.getRefreshInfo().getBuildMode().equals(BuildMode.IMMEDIATE)) {
+            jobExecutionConfiguration.setImmediate(true);
+        }
         jobExecutionConfiguration.setTimerDefinition(timerDefinition);
     }
 
diff --git a/regression-test/data/mtmv_p0/test_start_time_mtmv.out 
b/regression-test/data/mtmv_p0/test_start_time_mtmv.out
new file mode 100644
index 00000000000..8e17dcacec9
--- /dev/null
+++ b/regression-test/data/mtmv_p0/test_start_time_mtmv.out
@@ -0,0 +1,17 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !init --
+1      1
+2      2
+3      3
+
+-- !create --
+EVERY 2 HOUR STARTS 9999-12-13 21:07:09
+
+-- !alter --
+EVERY 2 HOUR STARTS 9998-12-13 21:07:09
+
+-- !refresh --
+1      1
+2      2
+3      3
+
diff --git a/regression-test/suites/mtmv_p0/test_start_time_mtmv.groovy 
b/regression-test/suites/mtmv_p0/test_start_time_mtmv.groovy
new file mode 100644
index 00000000000..89872adc253
--- /dev/null
+++ b/regression-test/suites/mtmv_p0/test_start_time_mtmv.groovy
@@ -0,0 +1,76 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.junit.Assert;
+
+suite("test_start_time_mtmv","mtmv") {
+    String suiteName = "test_start_time_mtmv"
+    String tableName = "${suiteName}_table"
+    String mvName = "${suiteName}_mv"
+
+    sql """drop table if exists `${tableName}`"""
+    sql """drop materialized view if exists ${mvName};"""
+
+    sql """
+        CREATE TABLE ${tableName}
+        (
+            k2 INT,
+            k3 varchar(32)
+        )
+        DISTRIBUTED BY HASH(k2) BUCKETS 2
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+        """
+
+    sql """
+        insert into ${tableName} values(1,1),(2,2),(3,3);
+        """
+
+    sql """
+        CREATE MATERIALIZED VIEW ${mvName}
+        BUILD immediate REFRESH AUTO ON SCHEDULE EVERY 2 HOUR STARTS 
"9999-12-13 21:07:09"
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES (
+        'replication_num' = '1'
+        )
+        AS
+        SELECT * from ${tableName};
+        """
+
+    waitingMTMVTaskFinishedByMvName(mvName)
+    order_qt_init "SELECT * FROM ${mvName}"
+
+    order_qt_create "select RecurringStrategy from jobs('type'='mv') where 
MvName='${mvName}'"
+
+    sql """
+       alter MATERIALIZED VIEW ${mvName} REFRESH auto ON SCHEDULE EVERY 2 HOUR 
STARTS "9998-12-13 21:07:09";
+        """
+
+    order_qt_alter "select RecurringStrategy from jobs('type'='mv') where 
MvName='${mvName}'"
+
+   // refresh mv
+    sql """
+       REFRESH MATERIALIZED VIEW ${mvName} complete
+       """
+
+    waitingMTMVTaskFinishedByMvName(mvName)
+    order_qt_refresh "SELECT * FROM ${mvName}"
+
+    sql """drop table if exists `${tableName}`"""
+    sql """drop materialized view if exists ${mvName};"""
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to