This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 373d9ab9880510b15e9441d62479ac4ee6792df0 Author: zhangdong <[email protected]> AuthorDate: Thu May 30 12:26:50 2024 +0800 [enhance](mtmv)add truncate table case (#35599) truncate table or truncate partition,mtmv should can detect data change --- .../data/mtmv_p0/test_truncate_table_mtmv.out | 12 +++ .../org/apache/doris/regression/suite/Suite.groovy | 22 ++++++ .../suites/mtmv_p0/test_truncate_table_mtmv.groovy | 87 ++++++++++++++++++++++ 3 files changed, 121 insertions(+) diff --git a/regression-test/data/mtmv_p0/test_truncate_table_mtmv.out b/regression-test/data/mtmv_p0/test_truncate_table_mtmv.out new file mode 100644 index 00000000000..1cbcc0cd370 --- /dev/null +++ b/regression-test/data/mtmv_p0/test_truncate_table_mtmv.out @@ -0,0 +1,12 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !init -- +1 1 +2 2 +3 3 + +-- !truncate_partition -- +2 2 +3 3 + +-- !truncate_table -- + diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy index 3aa59476707..fae2d7382b5 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy @@ -1033,6 +1033,28 @@ class Suite implements GroovyInterceptable { return debugPoint } + void waitingMTMVTaskFinishedByMvName(String mvName) { + Thread.sleep(2000); + String showTasks = "select TaskId,JobId,JobName,MvId,Status,MvName,MvDatabaseName,ErrorMsg from tasks('type'='mv') where MvName = '${mvName}' order by CreateTime ASC" + String status = "NULL" + List<List<Object>> result + long startTime = System.currentTimeMillis() + long timeoutTimestamp = startTime + 5 * 60 * 1000 // 5 min + do { + result = sql(showTasks) + logger.info("result: " + result.toString()) + if (!result.isEmpty()) { + status = result.last().get(4) + } + logger.info("The state of ${showTasks} is ${status}") + Thread.sleep(1000); + } while (timeoutTimestamp > System.currentTimeMillis() && (status == 'PENDING' || status == 'RUNNING' || status == 'NULL')) + if (status != "SUCCESS") { + logger.info("status is not success") + } + Assert.assertEquals("SUCCESS", status) + } + void waitingPartitionIsExpected(String tableName, String partitionName, boolean expectedStatus) { Thread.sleep(2000); String showPartitions = "show partitions from ${tableName}" diff --git a/regression-test/suites/mtmv_p0/test_truncate_table_mtmv.groovy b/regression-test/suites/mtmv_p0/test_truncate_table_mtmv.groovy new file mode 100644 index 00000000000..3e390d0c905 --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_truncate_table_mtmv.groovy @@ -0,0 +1,87 @@ +// 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_truncate_table_mtmv","mtmv") { + String suiteName = "test_truncate_table_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 TINYINT, + k3 INT not null + ) + COMMENT "my first table" + PARTITION BY LIST(`k3`) + ( + PARTITION `p1` VALUES IN ('1'), + PARTITION `p2` VALUES IN ('2'), + PARTITION `p3` VALUES IN ('3') + ) + DISTRIBUTED BY HASH(k2) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName} + BUILD DEFERRED REFRESH AUTO ON MANUAL + partition by(`k3`) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName}; + """ + + sql """ + insert into ${tableName} values(1,1),(2,2),(3,3); + """ + sql """ + REFRESH MATERIALIZED VIEW ${mvName} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName) + + // truncate partition + order_qt_init "SELECT * FROM ${mvName}" + sql """ + truncate table ${tableName} partition(p1); + """ + sql """ + REFRESH MATERIALIZED VIEW ${mvName} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName) + order_qt_truncate_partition "SELECT * FROM ${mvName}" + + // truncate table + sql """ + truncate table ${tableName}; + """ + sql """ + REFRESH MATERIALIZED VIEW ${mvName} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName) + order_qt_truncate_table "SELECT * FROM ${mvName}" + 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]
