diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java index ac359d1eb7..ddaf27fa53 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java @@ -244,7 +244,7 @@ public class ShowDataStmt extends ShowStmt { } OlapTable olapTable = (OlapTable) db - .getTableOrMetaException(tableName.getTbl(), TableType.OLAP, TableType.MATERIALIZED_VIEW); + .getTableOrMetaException(tableName.getTbl(), TableType.OLAP); long totalSize = 0; long totalReplicaCount = 0; long totalRemoteSize = 0; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java index f6e9b06e0b..1591e75232 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java @@ -125,8 +125,7 @@ public class ShowPartitionsStmt extends ShowStmt { } DatabaseIf db = catalog.getDbOrAnalysisException(dbName); - TableIf table = db.getTableOrMetaException(tblName, Table.TableType.OLAP, TableType.MATERIALIZED_VIEW, - TableType.HMS_EXTERNAL_TABLE); + TableIf table = db.getTableOrMetaException(tblName, Table.TableType.OLAP, TableType.HMS_EXTERNAL_TABLE); if (table instanceof HMSExternalTable) { if (((HMSExternalTable) table).isView()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java index 46ed88e72f..985296c366 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java @@ -17,6 +17,7 @@ package org.apache.doris.catalog; +import org.apache.doris.catalog.TableIf.TableType; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.DdlException; import org.apache.doris.common.ErrorCode; @@ -31,6 +32,7 @@ import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -158,9 +160,10 @@ public interface DatabaseIf { default T getTableOrMetaException(String tableName, TableIf.TableType tableType) throws MetaNotFoundException { T table = getTableOrMetaException(tableName); - if (table.getType() != tableType) { + TableType type = Objects.requireNonNull(table.getType()); + if (type != tableType && type.getParentType() != tableType) { throw new MetaNotFoundException( - "table type is not " + tableType + ", tableName=" + tableName + ", type=" + table.getType()); + "table type is not " + tableType + ", tableName=" + tableName + ", type=" + type); } return table; } @@ -168,7 +171,8 @@ public interface DatabaseIf { default T getTableOrMetaException(String tableName, List tableTypes) throws MetaNotFoundException { T table = getTableOrMetaException(tableName); - if (!tableTypes.contains(table.getType())) { + TableType type = Objects.requireNonNull(table.getType()); + if (!tableTypes.contains(type) && !tableTypes.contains(type.getParentType())) { throw new MetaNotFoundException( "Type of " + tableName + " doesn't match, expected data tables=" + tableTypes); } @@ -182,9 +186,10 @@ public interface DatabaseIf { default T getTableOrMetaException(long tableId, TableIf.TableType tableType) throws MetaNotFoundException { T table = getTableOrMetaException(tableId); - if (table.getType() != tableType) { + TableType type = Objects.requireNonNull(table.getType()); + if (type != tableType && type.getParentType() != tableType) { throw new MetaNotFoundException( - "table type is not " + tableType + ", tableId=" + tableId + ", type=" + table.getType()); + "table type is not " + tableType + ", tableId=" + tableId + ", type=" + type); } return table; } @@ -192,7 +197,8 @@ public interface DatabaseIf { default T getTableOrMetaException(long tableId, List tableTypes) throws MetaNotFoundException { T table = getTableOrMetaException(tableId); - if (!tableTypes.contains(table.getType())) { + TableType type = Objects.requireNonNull(table.getType()); + if (!tableTypes.contains(type) && !tableTypes.contains(type.getParentType())) { throw new MetaNotFoundException( "Type of " + tableId + " doesn't match, expected data tables=" + tableTypes); } @@ -205,9 +211,10 @@ public interface DatabaseIf { default T getTableOrDdlException(String tableName, TableIf.TableType tableType) throws DdlException { T table = getTableOrDdlException(tableName); - if (table.getType() != tableType) { + TableType type = Objects.requireNonNull(table.getType()); + if (type != tableType && type.getParentType() != tableType) { throw new DdlException( - "table type is not " + tableType + ", tableName=" + tableName + ", type=" + table.getType()); + "table type is not " + tableType + ", tableName=" + tableName + ", type=" + type); } return table; } @@ -218,9 +225,10 @@ public interface DatabaseIf { default T getTableOrDdlException(long tableId, TableIf.TableType tableType) throws DdlException { T table = getTableOrDdlException(tableId); - if (table.getType() != tableType) { + TableType type = Objects.requireNonNull(table.getType()); + if (type != tableType && type.getParentType() != tableType) { throw new DdlException( - "table type is not " + tableType + ", tableId=" + tableId + ", type=" + table.getType()); + "table type is not " + tableType + ", tableId=" + tableId + ", type=" + type); } return table; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java index 3539d17e26..6927538958 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java @@ -198,6 +198,15 @@ public interface TableIf { } } + public TableType getParentType() { + switch (this) { + case MATERIALIZED_VIEW: + return OLAP; + default: + return this; + } + } + public String toMysqlType() { switch (this) { case OLAP: