From 1b44b3307d6d8ac5d3b4812bb7e5a5b21cadaa1f Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 15:11:01 +0800 Subject: [PATCH 01/10] 1 --- .../org/apache/doris/nereids/DorisParser.g4 | 1 + .../java/org/apache/doris/alter/Alter.java | 8 ++ .../nereids/parser/LogicalPlanBuilder.java | 6 ++ .../plans/commands/info/AlterMTMVInfo.java | 10 ++ .../commands/info/AlterMTMVRenameInfo.java | 1 + .../commands/info/AlterMTMVReplaceInfo.java | 101 ++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVReplaceInfo.java diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 8ac823200ee3a0..a608be37963bb4 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -108,6 +108,7 @@ statementBase | REFRESH MATERIALIZED VIEW mvName=multipartIdentifier (partitionSpec | COMPLETE | AUTO) #refreshMTMV | ALTER MATERIALIZED VIEW mvName=multipartIdentifier ((RENAME newName=identifier) | (REFRESH (refreshMethod | refreshTrigger | refreshMethod refreshTrigger)) + | REPLACE WITH MATERIALIZED VIEW newName=identifier propertyClause? | (SET LEFT_PAREN fileProperties=propertyItemList RIGHT_PAREN)) #alterMTMV | DROP MATERIALIZED VIEW (IF EXISTS)? mvName=multipartIdentifier #dropMTMV | PAUSE MATERIALIZED VIEW JOB ON mvName=multipartIdentifier #pauseMTMV diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index a029f604dfdc61..ebf217b18c056d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -518,6 +518,11 @@ private void processReplaceTable(Database db, OlapTable origTable, List tableTypes = Lists.newArrayList(TableType.OLAP, TableType.MATERIALIZED_VIEW); @@ -604,6 +609,9 @@ private void replaceTableInternal(Database db, OlapTable origTable, OlapTable ne } else { // not swap, the origin table is not used anymore, need to drop all its tablets. Env.getCurrentEnv().onEraseOlapTable(origTable, isReplay); + if (origTable.getType() == TableType.MATERIALIZED_VIEW) { + Env.getCurrentEnv().getMtmvService().deregisterMTMV((MTMV) origTable); + } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index abc3c75fb207f5..a7bbf4da30ec20 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -398,6 +398,7 @@ import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVPropertyInfo; import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVRefreshInfo; import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVRenameInfo; +import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVReplaceInfo; import org.apache.doris.nereids.trees.plans.commands.info.AlterViewInfo; import org.apache.doris.nereids.trees.plans.commands.info.BulkLoadDataDesc; import org.apache.doris.nereids.trees.plans.commands.info.BulkStorageDesc; @@ -851,6 +852,11 @@ public AlterMTMVCommand visitAlterMTMV(AlterMTMVContext ctx) { } else if (ctx.SET() != null) { alterMTMVInfo = new AlterMTMVPropertyInfo(mvName, Maps.newHashMap(visitPropertyItemList(ctx.fileProperties))); + } else if (ctx.REPLACE() != null) { + String newName = ctx.newName.getText(); + Map properties = ctx.propertyClause() != null + ? Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : Maps.newHashMap(); + alterMTMVInfo = new AlterMTMVReplaceInfo(mvName, newName, properties); } return new AlterMTMVCommand(alterMTMVInfo); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVInfo.java index 3766de9b9815ac..7425ad1b0232f9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVInfo.java @@ -18,6 +18,8 @@ package org.apache.doris.nereids.trees.plans.commands.info; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.TableIf.TableType; +import org.apache.doris.common.DdlException; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.UserException; import org.apache.doris.mysql.privilege.PrivPredicate; @@ -51,6 +53,14 @@ public void analyze(ConnectContext ctx) throws AnalysisException { mvName.getDb() + ": " + mvName.getTbl()); throw new AnalysisException(message); } + // check mv exist + try { + Env.getCurrentInternalCatalog().getDbOrAnalysisException(mvName.getDb()) + .getTableOrDdlException(mvName.getTbl(), + TableType.MATERIALIZED_VIEW); + } catch (DdlException | org.apache.doris.common.AnalysisException e) { + throw new AnalysisException(e.getMessage(), e); + } } public abstract void run() throws UserException; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVRenameInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVRenameInfo.java index a93c53087d3cac..c86626b5920cca 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVRenameInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVRenameInfo.java @@ -61,5 +61,6 @@ public void run() throws DdlException { Database db = Env.getCurrentInternalCatalog().getDbOrDdlException(mvName.getDb()); Table table = db.getTableOrDdlException(mvName.getTbl()); Env.getCurrentEnv().renameTable(db, table, newName); + Env.getCurrentEnv().getMtmvService().alterTable(table); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVReplaceInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVReplaceInfo.java new file mode 100644 index 00000000000000..440db1e1400cdc --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterMTMVReplaceInfo.java @@ -0,0 +1,101 @@ +// 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. + +package org.apache.doris.nereids.trees.plans.commands.info; + +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.MTMV; +import org.apache.doris.catalog.TableIf.TableType; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.ErrorCode; +import org.apache.doris.common.UserException; +import org.apache.doris.common.util.PropertyAnalyzer; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.qe.ConnectContext; + +import java.util.Map; +import java.util.Objects; + +/** + * replace + */ +public class AlterMTMVReplaceInfo extends AlterMTMVInfo { + protected final String newName; + private final Map properties; + + // parsed from properties. + // if false, after replace, there will be only one table exist with. + // if true, the new table and the old table will be exchanged. + // default is true. + private boolean swapTable; + + /** + * constructor for alter MTMV + */ + public AlterMTMVReplaceInfo(TableNameInfo mvName, String newName, Map properties) { + super(mvName); + this.newName = Objects.requireNonNull(newName, "require newName object"); + this.properties = Objects.requireNonNull(properties, "require properties object"); + } + + /** + * analyze + * + * @param ctx ctx + * @throws AnalysisException AnalysisException + */ + public void analyze(ConnectContext ctx) throws AnalysisException { + super.analyze(ctx); + if (!Env.getCurrentEnv().getAccessManager().checkTblPriv(ctx, mvName.getCtl(), mvName.getDb(), + newName, PrivPredicate.ALTER)) { + String message = ErrorCode.ERR_TABLEACCESS_DENIED_ERROR.formatErrorMsg("ALTER", + ctx.getQualifiedUser(), ctx.getRemoteIP(), + mvName.getDb() + ": " + newName); + throw new AnalysisException(message); + } + this.swapTable = PropertyAnalyzer.analyzeBooleanProp(properties, PropertyAnalyzer.PROPERTIES_SWAP_TABLE, true); + + if (properties != null && !properties.isEmpty()) { + throw new AnalysisException("Unknown properties: " + properties.keySet()); + } + // check new mv exist + try { + Env.getCurrentInternalCatalog().getDbOrAnalysisException(mvName.getDb()) + .getTableOrDdlException(newName, + TableType.MATERIALIZED_VIEW); + } catch (DdlException | org.apache.doris.common.AnalysisException e) { + throw new AnalysisException(e.getMessage(), e); + } + } + + @Override + public void run() throws UserException { + Database db = Env.getCurrentInternalCatalog().getDbOrDdlException(mvName.getDb()); + MTMV mtmv = (MTMV) db.getTableOrDdlException(mvName.getTbl(), TableType.MATERIALIZED_VIEW); + MTMV newMtmv = (MTMV) db.getTableOrDdlException(newName, TableType.MATERIALIZED_VIEW); + Env.getCurrentEnv().getAlterInstance().processReplaceTable(db, mtmv, newName, swapTable); + Env.getCurrentEnv().getMtmvService().alterTable(newMtmv); + if (swapTable) { + Env.getCurrentEnv().getMtmvService().alterTable(mtmv); + } else { + Env.getCurrentEnv().getMtmvService().dropMTMV(mtmv); + Env.getCurrentEnv().getMtmvService().dropTable(mtmv); + } + } +} From a1a6ac196c8effa8f345c700bb571fc09337bb4f Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 15:54:21 +0800 Subject: [PATCH 02/10] 1 --- .../suites/mtmv_p0/test_replace_mtmv.groovy | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 regression-test/suites/mtmv_p0/test_replace_mtmv.groovy diff --git a/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy new file mode 100644 index 00000000000000..8f3454911484f9 --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy @@ -0,0 +1,139 @@ +// 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_replace_mtmv","mtmv") { + String dbName = context.config.getDbNameByFile(context.file) + String suiteName = "test_replace_mtmv" + String tableName1 = "${suiteName}_table1" + String tableName2 = "${suiteName}_table2" + String mvName1 = "${suiteName}_mv1" + String mvName2 = "${suiteName}_mv2" + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName2};""" + + sql """ + CREATE TABLE ${tableName1} + ( + k1 TINYINT, + k2 INT not null + ) + DISTRIBUTED BY HASH(k2) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE TABLE ${tableName2} + ( + k3 TINYINT, + k4 INT not null + ) + DISTRIBUTED BY HASH(k4) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName1} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName1}; + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName2} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName2}; + """ + sql """ + insert into ${tableName1} values(1,1); + """ + sql """ + REFRESH MATERIALIZED VIEW ${mvName1} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName1) + + order_qt_mv1 "SELECT * FROM ${mvName1}" + + + sql """ + insert into ${tableName2} values(2,2); + """ + sql """ + REFRESH MATERIALIZED VIEW ${mvName2} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName2) + + order_qt_mv2 "SELECT * FROM ${mvName2}" + + sql """ + alter MATERIALIZED VIEW ${mvName1} replace with MATERIALIZED VIEW ${mvName2}; + """ + order_qt_mv1_replace "SELECT * FROM ${mvName1}" + order_qt_mv2_replace "SELECT * FROM ${mvName2}" + + sql """ + insert into ${tableName1} values(3,3); + """ + sql """ + insert into ${tableName2} values(4,4); + """ + + sql """ + REFRESH MATERIALIZED VIEW ${mvName1} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName1) + + order_qt_mv1_refresh "SELECT * FROM ${mvName1}" + + sql """ + REFRESH MATERIALIZED VIEW ${mvName2} AUTO + """ + waitingMTMVTaskFinishedByMvName(mvName2) + + order_qt_mv2_refresh "SELECT * FROM ${mvName2}" + + + sql """ + alter MATERIALIZED VIEW ${mvName1} replace with MATERIALIZED VIEW ${mvName2} PROPERTIES('swap' = 'false'); + """ + + def mvResult = sql """select Name from mv_infos("database"="${dbName}");""" + logger.info("mvResult: " + mvResult.toString()) + assertFalse(mvResult.toString().contains("${mvName1}")) + + def jobResult = sql """select MvName from jobs("type"="mv");""" + logger.info("jobResult: " + jobResult.toString()) + assertFalse(jobResult.toString().contains("${mvName1}")) + + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName2};""" +} From 6a943e72206cda039cc25bb0a74bf256a6f66050 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:01:01 +0800 Subject: [PATCH 03/10] 1 --- regression-test/suites/mtmv_p0/test_replace_mtmv.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy index 8f3454911484f9..08d521708b1368 100644 --- a/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy @@ -126,11 +126,13 @@ suite("test_replace_mtmv","mtmv") { def mvResult = sql """select Name from mv_infos("database"="${dbName}");""" logger.info("mvResult: " + mvResult.toString()) - assertFalse(mvResult.toString().contains("${mvName1}")) + assertFalse(mvResult.toString().contains("${mvName2}")) def jobResult = sql """select MvName from jobs("type"="mv");""" logger.info("jobResult: " + jobResult.toString()) - assertFalse(jobResult.toString().contains("${mvName1}")) + assertFalse(jobResult.toString().contains("${mvName2}")) + + order_qt_mv1_replace_not_swap "SELECT * FROM ${mvName1}" sql """drop table if exists `${tableName1}`""" sql """drop table if exists `${tableName2}`""" From 6687baf6ff67db9d30f39b90864589f58c21083e Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:05:39 +0800 Subject: [PATCH 04/10] 1 --- .../data/mtmv_p0/test_replace_mtmv.out | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 regression-test/data/mtmv_p0/test_replace_mtmv.out diff --git a/regression-test/data/mtmv_p0/test_replace_mtmv.out b/regression-test/data/mtmv_p0/test_replace_mtmv.out new file mode 100644 index 00000000000000..7e38e4e8e2e368 --- /dev/null +++ b/regression-test/data/mtmv_p0/test_replace_mtmv.out @@ -0,0 +1,25 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !mv1 -- +1 1 + +-- !mv2 -- +2 2 + +-- !mv1_replace -- +2 2 + +-- !mv2_replace -- +1 1 + +-- !mv1_refresh -- +2 2 +4 4 + +-- !mv2_refresh -- +1 1 +3 3 + +-- !mv1_replace_not_swap -- +1 1 +3 3 + From e00a4c3f9b377b71d88da1eeb30cf37478350be0 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:23:22 +0800 Subject: [PATCH 05/10] 1 --- .../test_multi_level_replace_mtmv.groovy | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy diff --git a/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy b/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy new file mode 100644 index 00000000000000..01c50e47ebef4f --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy @@ -0,0 +1,88 @@ +// 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_multi_level_replace_mtmv","mtmv") { + String dbName = context.config.getDbNameByFile(context.file) + String suiteName = "test_multi_level_replace_mtmv" + String tableName1 = "${suiteName}_table1" + String tableName2 = "${suiteName}_table2" + String mvName1 = "${suiteName}_mv1" + String mvName1_replace = "${suiteName}_mv1_replace" + String mvName2 = "${suiteName}_mv2" + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName1_replace};""" + sql """drop materialized view if exists ${mvName2};""" + + sql """ + CREATE TABLE ${tableName1} + ( + k1 TINYINT, + k2 INT not null + ) + DISTRIBUTED BY HASH(k2) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE TABLE ${tableName2} + ( + k3 TINYINT, + k4 INT not null + ) + DISTRIBUTED BY HASH(k4) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName1} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName1}; + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName2} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${mvName1}; + """ + + sql """ + alter MATERIALIZED VIEW ${mvName1} replace with MATERIALIZED VIEW ${mvName1_replace}; + """ + + order_qt_status "select Name,State from mv_infos('database'='${dbName}') where Name='${mvName2}'" + + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName1_replace};""" + sql """drop materialized view if exists ${mvName2};""" +} From a3da44018f8fcbdae4da9ceb4910d1ffe2cca853 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:25:24 +0800 Subject: [PATCH 06/10] 1 --- .../mtmv_p0/test_multi_level_replace_mtmv.groovy | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy b/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy index 01c50e47ebef4f..0b99f1b452ba63 100644 --- a/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_multi_level_replace_mtmv.groovy @@ -63,6 +63,16 @@ suite("test_multi_level_replace_mtmv","mtmv") { AS SELECT * from ${tableName1}; """ + sql """ + CREATE MATERIALIZED VIEW ${mvName1_replace} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName1}; + """ sql """ CREATE MATERIALIZED VIEW ${mvName2} BUILD DEFERRED REFRESH AUTO ON MANUAL From 64ffda3bf3fb06919095809b5f44d6fea9a554f4 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:26:28 +0800 Subject: [PATCH 07/10] 1 --- .../data/mtmv_p0/test_multi_level_replace_mtmv.out | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 regression-test/data/mtmv_p0/test_multi_level_replace_mtmv.out diff --git a/regression-test/data/mtmv_p0/test_multi_level_replace_mtmv.out b/regression-test/data/mtmv_p0/test_multi_level_replace_mtmv.out new file mode 100644 index 00000000000000..552fee78be9368 --- /dev/null +++ b/regression-test/data/mtmv_p0/test_multi_level_replace_mtmv.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !status -- +test_multi_level_replace_mtmv_mv2 SCHEMA_CHANGE + From e7af42b864f55de6faa5161aa5fa6189e3fad0b9 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:30:23 +0800 Subject: [PATCH 08/10] 1 --- .../test_multi_level_rename_mtmv.groovy | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 regression-test/suites/mtmv_p0/test_multi_level_rename_mtmv.groovy diff --git a/regression-test/suites/mtmv_p0/test_multi_level_rename_mtmv.groovy b/regression-test/suites/mtmv_p0/test_multi_level_rename_mtmv.groovy new file mode 100644 index 00000000000000..35537662a236b4 --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_multi_level_rename_mtmv.groovy @@ -0,0 +1,88 @@ +// 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_multi_level_rename_mtmv","mtmv") { + String dbName = context.config.getDbNameByFile(context.file) + String suiteName = "test_multi_level_rename_mtmv" + String tableName1 = "${suiteName}_table1" + String tableName2 = "${suiteName}_table2" + String mvName1 = "${suiteName}_mv1" + String mvName1_rename = "${suiteName}_mv1_rename" + String mvName2 = "${suiteName}_mv2" + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName1_rename};""" + sql """drop materialized view if exists ${mvName2};""" + + sql """ + CREATE TABLE ${tableName1} + ( + k1 TINYINT, + k2 INT not null + ) + DISTRIBUTED BY HASH(k2) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE TABLE ${tableName2} + ( + k3 TINYINT, + k4 INT not null + ) + DISTRIBUTED BY HASH(k4) BUCKETS 2 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName1} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${tableName1}; + """ + sql """ + CREATE MATERIALIZED VIEW ${mvName2} + BUILD DEFERRED REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ( + 'replication_num' = '1' + ) + AS + SELECT * from ${mvName1}; + """ + + sql """ + alter MATERIALIZED VIEW ${mvName1} rename ${mvName1_rename}; + """ + + order_qt_status "select Name,State from mv_infos('database'='${dbName}') where Name='${mvName2}'" + + sql """drop table if exists `${tableName1}`""" + sql """drop table if exists `${tableName2}`""" + sql """drop materialized view if exists ${mvName1};""" + sql """drop materialized view if exists ${mvName1_rename};""" + sql """drop materialized view if exists ${mvName2};""" +} From de69289aa62962614b12fcbd2e28852bd1f52a71 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:31:44 +0800 Subject: [PATCH 09/10] 1 --- regression-test/data/mtmv_p0/test_multi_level_rename_mtmv.out | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 regression-test/data/mtmv_p0/test_multi_level_rename_mtmv.out diff --git a/regression-test/data/mtmv_p0/test_multi_level_rename_mtmv.out b/regression-test/data/mtmv_p0/test_multi_level_rename_mtmv.out new file mode 100644 index 00000000000000..b48dc194db39f2 --- /dev/null +++ b/regression-test/data/mtmv_p0/test_multi_level_rename_mtmv.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !status -- +test_multi_level_rename_mtmv_mv2 SCHEMA_CHANGE + From d0156a6f49ef89d6771bf1c501b52441224ce051 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Mon, 24 Jun 2024 16:38:29 +0800 Subject: [PATCH 10/10] 1 --- .../suites/mtmv_p0/test_replace_mtmv.groovy | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy index 08d521708b1368..f7e0eab9640631 100644 --- a/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_replace_mtmv.groovy @@ -92,6 +92,20 @@ suite("test_replace_mtmv","mtmv") { order_qt_mv2 "SELECT * FROM ${mvName2}" + test { + sql """ + alter MATERIALIZED VIEW ${mvName1} replace with MATERIALIZED VIEW ${tableName1}; + """ + exception "MATERIALIZED_VIEW" + } + + test { + sql """ + alter MATERIALIZED VIEW ${tableName1} replace with MATERIALIZED VIEW ${mvName1}; + """ + exception "MATERIALIZED_VIEW" + } + sql """ alter MATERIALIZED VIEW ${mvName1} replace with MATERIALIZED VIEW ${mvName2}; """