Skip to content

Commit

Permalink
handle exception when alter or rename table and add check system data…
Browse files Browse the repository at this point in the history
…base for database api
  • Loading branch information
jerry-024 committed Dec 19, 2024
1 parent 28c0a65 commit 95103ae
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,6 +187,7 @@ public List<String> listDatabases() {
@Override
public void createDatabase(String name, boolean ignoreIfExists, Map<String, String> properties)
throws DatabaseAlreadyExistException {
checkNotSystemDatabase(name);
CreateDatabaseRequest request = new CreateDatabaseRequest(name, properties);
try {
client.post(
Expand All @@ -198,6 +201,9 @@ public void createDatabase(String name, boolean ignoreIfExists, Map<String, Stri

@Override
public Database getDatabase(String name) throws DatabaseNotExistException {
if (isSystemDatabase(name)) {
return Database.of(name);
}
try {
GetDatabaseResponse response =
client.get(resourcePaths.database(name), GetDatabaseResponse.class, headers());
Expand All @@ -211,6 +217,7 @@ public Database getDatabase(String name) throws DatabaseNotExistException {
@Override
public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
throws DatabaseNotExistException, DatabaseNotEmptyException {
checkNotSystemDatabase(name);
try {
if (!cascade && !this.listTables(name).isEmpty()) {
throw new DatabaseNotEmptyException(name);
Expand All @@ -226,6 +233,7 @@ public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade
@Override
public void alterDatabase(String name, List<PropertyChange> changes, boolean ignoreIfNotExists)
throws DatabaseNotExistException {
checkNotSystemDatabase(name);
try {
Pair<Map<String, String>, Set<String>> setPropertiesToRemoveKeys =
PropertyChange.getSetPropertiesToRemoveKeys(changes);
Expand Down Expand Up @@ -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<SchemaChange> 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
Expand Down

0 comments on commit 95103ae

Please sign in to comment.