From 55b0acb528d7701e8b66e74b868c31eb107b1881 Mon Sep 17 00:00:00 2001 From: zhangwl9 <1298877813@qq.com> Date: Fri, 22 Nov 2024 15:35:15 +0800 Subject: [PATCH] [AMORO-3330] Reducing redundant 'databaseExists' in 'CommonUnifiedCatalog' (#3339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reducing redundant 'databaseExists' in 'CommonUnifiedCatalog' Co-authored-by: 张文领 --- .../java/org/apache/amoro/CommonUnifiedCatalog.java | 10 ---------- .../apache/amoro/formats/hudi/HudiHadoopCatalog.java | 8 +++++++- .../org/apache/amoro/formats/mixed/MixedCatalog.java | 11 ++++++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/amoro-common/src/main/java/org/apache/amoro/CommonUnifiedCatalog.java b/amoro-common/src/main/java/org/apache/amoro/CommonUnifiedCatalog.java index b49d860fbb..573cf42a03 100644 --- a/amoro-common/src/main/java/org/apache/amoro/CommonUnifiedCatalog.java +++ b/amoro-common/src/main/java/org/apache/amoro/CommonUnifiedCatalog.java @@ -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."); } @@ -148,9 +141,6 @@ public String name() { @Override public List listTables(String database) { - if (!databaseExists(database)) { - throw new NoSuchDatabaseException("Database: " + database + " does not exist."); - } TableFormat[] formats = new TableFormat[] { TableFormat.MIXED_HIVE, diff --git a/amoro-format-hudi/src/main/java/org/apache/amoro/formats/hudi/HudiHadoopCatalog.java b/amoro-format-hudi/src/main/java/org/apache/amoro/formats/hudi/HudiHadoopCatalog.java index b50f0b12f1..25d436a687 100644 --- a/amoro-format-hudi/src/main/java/org/apache/amoro/formats/hudi/HudiHadoopCatalog.java +++ b/amoro-format-hudi/src/main/java/org/apache/amoro/formats/hudi/HudiHadoopCatalog.java @@ -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; @@ -155,7 +156,12 @@ public List 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(); } diff --git a/amoro-format-iceberg/src/main/java/org/apache/amoro/formats/mixed/MixedCatalog.java b/amoro-format-iceberg/src/main/java/org/apache/amoro/formats/mixed/MixedCatalog.java index 4ed6a9ea6b..660293c472 100644 --- a/amoro-format-iceberg/src/main/java/org/apache/amoro/formats/mixed/MixedCatalog.java +++ b/amoro-format-iceberg/src/main/java/org/apache/amoro/formats/mixed/MixedCatalog.java @@ -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; @@ -76,9 +77,13 @@ public AmoroTable loadTable(String database, String table) { @Override public List 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