Skip to content

Commit

Permalink
[AMORO-3330] Reducing redundant 'databaseExists' in 'CommonUnifiedCat…
Browse files Browse the repository at this point in the history
…alog' (#3339)

Reducing redundant 'databaseExists' in 'CommonUnifiedCatalog'

Co-authored-by: 张文领 <[email protected]>
  • Loading branch information
zhangwl9 and 张文领 authored Nov 22, 2024
1 parent f88b7a6 commit 55b0acb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,11 @@ public boolean tableExists(String database, String table) {

@Override
public void createDatabase(String database) {
if (databaseExists(database)) {
throw new AlreadyExistsException("Database: " + database + " already exists.");
}

findFirstFormatCatalog(TableFormat.values()).createDatabase(database);
}

@Override
public void dropDatabase(String database) {
if (!databaseExists(database)) {
throw new NoSuchDatabaseException("Database: " + database + " does not exist.");
}
if (!listTables(database).isEmpty()) {
throw new IllegalStateException("Database: " + database + " is not empty.");
}
Expand Down Expand Up @@ -148,9 +141,6 @@ public String name() {

@Override
public List<TableIDWithFormat> listTables(String database) {
if (!databaseExists(database)) {
throw new NoSuchDatabaseException("Database: " + database + " does not exist.");
}
TableFormat[] formats =
new TableFormat[] {
TableFormat.MIXED_HIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.amoro.AmoroTable;
import org.apache.amoro.DatabaseNotEmptyException;
import org.apache.amoro.FormatCatalog;
import org.apache.amoro.NoSuchDatabaseException;
import org.apache.amoro.NoSuchTableException;
import org.apache.amoro.properties.CatalogMetaProperties;
import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
Expand Down Expand Up @@ -155,7 +156,12 @@ public List<String> listTables(String database) {
() -> {
FileSystem fs = fs();
Path databasePath = new Path(warehouse, database);
FileStatus[] items = fs.listStatus(databasePath);
FileStatus[] items;
try {
items = fs.listStatus(databasePath);
} catch (FileNotFoundException e) {
throw new NoSuchDatabaseException("Database: " + database + " is not exists", e);
}
if (items == null || items.length == 0) {
return Lists.newArrayList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.amoro.AmoroTable;
import org.apache.amoro.FormatCatalog;
import org.apache.amoro.NoSuchDatabaseException;
import org.apache.amoro.TableFormat;
import org.apache.amoro.mixed.MixedFormatCatalog;
import org.apache.amoro.table.MixedTable;
Expand Down Expand Up @@ -76,9 +77,13 @@ public AmoroTable<?> loadTable(String database, String table) {

@Override
public List<String> listTables(String database) {
return catalog.listTables(database).stream()
.map(TableIdentifier::getTableName)
.collect(Collectors.toList());
try {
return catalog.listTables(database).stream()
.map(TableIdentifier::getTableName)
.collect(Collectors.toList());
} catch (Exception e) {
throw new NoSuchDatabaseException("Database: " + database + " is not exists", e);
}
}

@Override
Expand Down

0 comments on commit 55b0acb

Please sign in to comment.