From 95103aeca70fedbe3cd057ea00efa00acc703c64 Mon Sep 17 00:00:00 2001 From: yantian Date: Thu, 19 Dec 2024 14:41:10 +0800 Subject: [PATCH] handle exception when alter or rename table and add check system database for database api --- .../org/apache/paimon/rest/RESTCatalog.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java index 335fe897e5c2..e56419d1c5ea 100644 --- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java @@ -76,6 +76,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.function.Supplier; +import static org.apache.paimon.catalog.CatalogUtils.checkNotSystemDatabase; +import static org.apache.paimon.catalog.CatalogUtils.isSystemDatabase; import static org.apache.paimon.catalog.CatalogUtils.lockContext; import static org.apache.paimon.catalog.CatalogUtils.lockFactory; import static org.apache.paimon.catalog.CatalogUtils.newTableLocation; @@ -185,6 +187,7 @@ public List listDatabases() { @Override public void createDatabase(String name, boolean ignoreIfExists, Map properties) throws DatabaseAlreadyExistException { + checkNotSystemDatabase(name); CreateDatabaseRequest request = new CreateDatabaseRequest(name, properties); try { client.post( @@ -198,6 +201,9 @@ public void createDatabase(String name, boolean ignoreIfExists, Map changes, boolean ignoreIfNotExists) throws DatabaseNotExistException { + checkNotSystemDatabase(name); try { Pair, Set> setPropertiesToRemoveKeys = PropertyChange.getSetPropertiesToRemoveKeys(changes); @@ -305,22 +313,40 @@ public void createTable(Identifier identifier, Schema schema, boolean ignoreIfEx @Override public void renameTable(Identifier fromTable, Identifier toTable, boolean ignoreIfNotExists) throws TableNotExistException, TableAlreadyExistException { - updateTable(fromTable, toTable, new ArrayList<>()); + try { + updateTable(fromTable, toTable, new ArrayList<>()); + } catch (NoSuchResourceException e) { + if (!ignoreIfNotExists) { + throw new TableNotExistException(fromTable); + } + } } @Override public void alterTable( Identifier identifier, List changes, boolean ignoreIfNotExists) throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException { - updateTable(identifier, null, changes); + try { + updateTable(identifier, null, changes); + } catch (NoSuchResourceException e) { + if (!ignoreIfNotExists) { + throw new TableNotExistException(identifier); + } + } } @Override public void dropTable(Identifier identifier, boolean ignoreIfNotExists) throws TableNotExistException { - client.delete( - resourcePaths.table(identifier.getDatabaseName(), identifier.getTableName()), - headers()); + try { + client.delete( + resourcePaths.table(identifier.getDatabaseName(), identifier.getTableName()), + headers()); + } catch (NoSuchResourceException e) { + if (!ignoreIfNotExists) { + throw new TableNotExistException(identifier); + } + } } @Override