Skip to content

Commit

Permalink
[fix](mtmv) Mtmv support set both immediate and starttime (apache#39573)
Browse files Browse the repository at this point in the history
extends: apache#36805

Previously, if the user set immediate execution, the current time would
replace the user's set start time
  • Loading branch information
zddr committed Sep 5, 2024
1 parent 40d10bd commit 6c6bc73
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ private void setScheduleJobConfig(JobExecutionConfiguration jobExecutionConfigur
.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);
}

Expand Down
17 changes: 17 additions & 0 deletions regression-test/data/mtmv_p0/test_start_time_mtmv.out
Original file line number Diff line number Diff line change
@@ -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

76 changes: 76 additions & 0 deletions regression-test/suites/mtmv_p0/test_start_time_mtmv.groovy
Original file line number Diff line number Diff line change
@@ -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};"""
}

0 comments on commit 6c6bc73

Please sign in to comment.