Skip to content

Commit

Permalink
[enhance](mtmv)support create mtmv with other mtmv (#32984)
Browse files Browse the repository at this point in the history
  • Loading branch information
zddr authored and Doris-Extras committed Apr 10, 2024
1 parent 77ad3f6 commit 0ab8b57
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.View;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
Expand Down Expand Up @@ -64,8 +63,6 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector;
import org.apache.doris.nereids.trees.plans.visitor.TableCollector;
import org.apache.doris.nereids.trees.plans.visitor.TableCollector.TableCollectorContext;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
Expand Down Expand Up @@ -319,14 +316,6 @@ private PartitionDesc generatePartitionDesc(MTMVRelatedTableIf relatedTable, Con
}

private void analyzeBaseTables(Plan plan) {
TableCollectorContext collectorContext =
new TableCollector.TableCollectorContext(Sets.newHashSet(TableType.MATERIALIZED_VIEW), true);
plan.accept(TableCollector.INSTANCE, collectorContext);
Set<TableIf> collectedTables = collectorContext.getCollectedTables();
if (!CollectionUtils.isEmpty(collectedTables)) {
throw new AnalysisException("can not contain MATERIALIZED_VIEW");
}

List<Object> subQuerys = plan.collectToList(node -> node instanceof LogicalSubQueryAlias);
for (Object subquery : subQuerys) {
List<String> qualifier = ((LogicalSubQueryAlias) subquery).getQualifier();
Expand Down
13 changes: 13 additions & 0 deletions regression-test/data/mtmv_p0/test_multi_level_mtmv.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !mv1 --
1 1

-- !mv2 --
1 1

-- !status1 --
multi_level_mtmv1 SCHEMA_CHANGE SUCCESS

-- !status2 --
multi_level_mtmv2 SCHEMA_CHANGE SUCCESS

15 changes: 0 additions & 15 deletions regression-test/suites/mtmv_p0/test_build_mtmv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,6 @@ suite("test_build_mtmv") {
log.info(e.getMessage())
}

// not allow create mv use other mv
try {
sql """
CREATE MATERIALIZED VIEW ${mvNameRenamed}
BUILD DEFERRED REFRESH COMPLETE ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES ('replication_num' = '1')
AS
SELECT * from ${mvName};
"""
Assert.fail();
} catch (Exception e) {
log.info(e.getMessage())
}

// not allow create mv use view
try {
sql """
Expand Down
81 changes: 81 additions & 0 deletions regression-test/suites/mtmv_p0/test_multi_level_mtmv.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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.

suite("test_multi_level_mtmv") {
def tableName = "t_test_multi_level_user"
def mv1 = "multi_level_mtmv1"
def mv2 = "multi_level_mtmv2"
def dbName = "regression_test_mtmv_p0"
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mv1};"""
sql """drop materialized view if exists ${mv2};"""

sql """
CREATE TABLE IF NOT EXISTS `${tableName}` (
k1 int,
k2 int
)
DISTRIBUTED BY HASH(k1) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);
"""
sql """
INSERT INTO ${tableName} VALUES(1,1);
"""

sql """
CREATE MATERIALIZED VIEW ${mv1}
BUILD DEFERRED REFRESH COMPLETE ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES ('replication_num' = '1')
AS
SELECT * FROM ${tableName};
"""
def jobName1 = getJobName("regression_test_mtmv_p0", mv1);
sql """
REFRESH MATERIALIZED VIEW ${mv1} AUTO
"""
waitingMTMVTaskFinished(jobName1)
order_qt_mv1 "select * from ${mv1}"

sql """
CREATE MATERIALIZED VIEW ${mv2}
BUILD DEFERRED REFRESH COMPLETE ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES ('replication_num' = '1')
AS
SELECT * FROM ${mv1};
"""
def jobName2 = getJobName("regression_test_mtmv_p0", mv2);
sql """
REFRESH MATERIALIZED VIEW ${mv2} AUTO
"""
waitingMTMVTaskFinished(jobName2)
order_qt_mv2 "select * from ${mv2}"

// drop table
sql """
drop table ${tableName}
"""
order_qt_status1 "select Name,State,RefreshState from mv_infos('database'='${dbName}') where Name='${mv1}'"
order_qt_status2 "select Name,State,RefreshState from mv_infos('database'='${dbName}') where Name='${mv2}'"

sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mv1};"""
sql """drop materialized view if exists ${mv2};"""
}

0 comments on commit 0ab8b57

Please sign in to comment.