From 8a7f49edf83295e5384354cfefc52f54571482cc Mon Sep 17 00:00:00 2001 From: Yulei-Yang Date: Thu, 19 Sep 2024 17:18:57 +0800 Subject: [PATCH] update --- .../java/org/apache/doris/alter/Alter.java | 2 +- .../org/apache/doris/catalog/Database.java | 19 ++++++++++++++++ .../org/apache/doris/catalog/DatabaseIf.java | 22 ++++++++++++++++--- .../doris/datasource/ExternalDatabase.java | 5 +++++ 4 files changed, 44 insertions(+), 4 deletions(-) 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 ee3531637b9abbc..860377a5ee99486 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 @@ -125,7 +125,7 @@ public void processCreateMaterializedView(CreateMaterializedViewStmt stmt) Database db = Env.getCurrentInternalCatalog().getDbOrDdlException(dbName); Env.getCurrentInternalCatalog().checkAvailableCapacity(db); - OlapTable olapTable = (OlapTable) db.getTableWithTypeOrMetaException(tableName, TableType.OLAP); + OlapTable olapTable = (OlapTable) db.getNonTempTableOrMetaException(tableName, TableType.OLAP); ((MaterializedViewHandler) materializedViewHandler).processCreateMaterializedView(stmt, db, olapTable); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java index 0b0ce30ae4932e8..19e839561190486 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java @@ -581,6 +581,25 @@ public Table getTableNullable(String tableName) { return table; } + /** + * This is a thread-safe method when nameToTable is a concurrent hash map + */ + @Override + public Table getNonTempTableNullable(String tableName) { + if (Env.isStoredTableNamesLowerCase()) { + tableName = tableName.toLowerCase(); + } + if (Env.isTableNamesCaseInsensitive()) { + tableName = lowerCaseToTableName.get(tableName.toLowerCase()); + if (tableName == null) { + return null; + } + } + + Table table = nameToTable.get(tableName); + return table; + } + /** * This is a thread-safe method when idToTable is a concurrent hash map */ 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 19462ee5dfa913b..34b5cd4f60d5b78 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 @@ -111,6 +111,8 @@ default Set getTableNamesOrEmptyWithLock() { T getTableNullable(String tableName); + T getNonTempTableNullable(String tableName); + default T getTableNullableIfException(String tableName) { try { return getTableNullable(tableName); @@ -139,6 +141,15 @@ default T getTableOrException(String tableName, java.util. return table; } + default T getNonTempTableOrException(String tableName, + java.util.function.Function e) throws E { + T table = getNonTempTableNullable(tableName); + if (table == null) { + throw e.apply(tableName); + } + return table; + } + default T getTableOrException(long tableId, Function e) throws E { T table = getTableNullable(tableId); if (table == null) { @@ -152,6 +163,11 @@ default T getTableOrMetaException(String tableName) throws MetaNotFoundException ErrorCode.ERR_BAD_TABLE_ERROR)); } + default T getNonTempTableOrMetaException(String tableName) throws MetaNotFoundException { + return getNonTempTableOrException(tableName, t -> new MetaNotFoundException("table not found, tableName=" + t, + ErrorCode.ERR_BAD_TABLE_ERROR)); + } + default T getTableOrMetaException(long tableId) throws MetaNotFoundException { return getTableOrException(tableId, t -> new MetaNotFoundException("table not found, tableId=" + t, ErrorCode.ERR_BAD_TABLE_ERROR)); @@ -167,11 +183,11 @@ default T getTableOrMetaException(String tableName, TableIf.TableType tableType) return table; } - default T getTableWithTypeOrMetaException(String tableName, TableIf.TableType tableType) + default T getNonTempTableOrMetaException(String tableName, TableIf.TableType tableType) throws MetaNotFoundException { - T table = getTableOrMetaException(tableName); + T table = getNonTempTableOrMetaException(tableName); TableType type = Objects.requireNonNull(table.getType()); - if (type != tableType) { + if (type != tableType && type.getParentType() != tableType) { throw new MetaNotFoundException( "table type is not " + tableType + ", tableName=" + tableName + ", type=" + type); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java index d653a5a178e484a..01eb6767561198d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java @@ -387,6 +387,11 @@ public T getTableNullable(String tableName) { } } + @Override + public T getNonTempTableNullable(String tableName) { + throw new NotImplementedException("getNonTempTableNullable() is not implemented"); + } + @Override public T getTableNullable(long tableId) { makeSureInitialized();