diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java b/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java index 6b8f59e650..19e2ac6b6b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java @@ -52,6 +52,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Collection; @@ -245,10 +246,14 @@ public class PartitionsProcDir implements ProcDirInterface { Joiner joiner = Joiner.on(", "); Map> partitionsUnSyncTables = null; + String mtmvPartitionSyncErrorMsg = null; if (olapTable instanceof MTMV) { - partitionsUnSyncTables = MTMVPartitionUtil - .getPartitionsUnSyncTables((MTMV) olapTable, partitionIds); - + try { + partitionsUnSyncTables = MTMVPartitionUtil + .getPartitionsUnSyncTables((MTMV) olapTable, partitionIds); + } catch (AnalysisException e) { + mtmvPartitionSyncErrorMsg = e.getMessage(); + } } for (Long partitionId : partitionIds) { Partition partition = olapTable.getPartition(partitionId); @@ -314,9 +319,15 @@ public class PartitionsProcDir implements ProcDirInterface { partitionInfo.add(tblPartitionInfo.getIsMutable(partitionId)); if (olapTable instanceof MTMV) { - List partitionUnSyncTables = partitionsUnSyncTables.get(partitionId); - partitionInfo.add(CollectionUtils.isEmpty(partitionUnSyncTables)); - partitionInfo.add(partitionUnSyncTables.toString()); + if (StringUtils.isEmpty(mtmvPartitionSyncErrorMsg)) { + List partitionUnSyncTables = partitionsUnSyncTables.getOrDefault(partitionId, + Lists.newArrayList()); + partitionInfo.add(CollectionUtils.isEmpty(partitionUnSyncTables)); + partitionInfo.add(partitionUnSyncTables.toString()); + } else { + partitionInfo.add(false); + partitionInfo.add(mtmvPartitionSyncErrorMsg); + } } else { partitionInfo.add(true); partitionInfo.add(FeConstants.null_string); diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java index f2b7b146ee..82a649be37 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java @@ -266,7 +266,9 @@ public class MTMVPartitionUtil { if (mtmv.getMvPartitionInfo().getPartitionType() != MTMVPartitionType.SELF_MANAGE && mtmv .getMvPartitionInfo().getRelatedTableInfo().equals(baseTableInfo)) { if (CollectionUtils.isEmpty(relatedPartitionNames)) { - throw new AnalysisException("can not found related partition"); + // can not found related partition + res.add(mtmvRelatedTableIf.getName()); + continue; } boolean isSyncWithPartition = isSyncWithPartitions(mtmv, partitionName, mtmvRelatedTableIf, relatedPartitionNames); diff --git a/regression-test/suites/mtmv_p0/test_show_partitions_mtmv.groovy b/regression-test/suites/mtmv_p0/test_show_partitions_mtmv.groovy new file mode 100644 index 0000000000..3575cbd80e --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_show_partitions_mtmv.groovy @@ -0,0 +1,72 @@ +// 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_show_partitions_mtmv","mtmv") { + String suiteName = "test_show_partitions_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}; + """ + + // drop partition of base table + sql """ + alter table ${tableName} drop partition p1; + """ + def dropPartitionResult = sql """show partitions from ${mvName}""" + logger.info("dropPartitionResult: " + dropPartitionResult.toString()) + + // drop base table + sql """drop table if exists `${tableName}`""" + + def dropTableResult = sql """show partitions from ${mvName}""" + logger.info("dropTableResult: " + dropTableResult.toString()) + + sql """drop table if exists `${tableName}`""" + sql """drop materialized view if exists ${mvName};""" +}