This is an automated email from the ASF dual-hosted git repository.

jinsongzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new 55b0acb52 [AMORO-3330] Reducing redundant 'databaseExists' in 
'CommonUnifiedCatalog' (#3339)
55b0acb52 is described below

commit 55b0acb528d7701e8b66e74b868c31eb107b1881
Author: zhangwl9 <[email protected]>
AuthorDate: Fri Nov 22 15:35:15 2024 +0800

    [AMORO-3330] Reducing redundant 'databaseExists' in 'CommonUnifiedCatalog' 
(#3339)
    
    Reducing redundant 'databaseExists' in 'CommonUnifiedCatalog'
    
    Co-authored-by: 张文领 <[email protected]>
---
 .../src/main/java/org/apache/amoro/CommonUnifiedCatalog.java  | 10 ----------
 .../java/org/apache/amoro/formats/hudi/HudiHadoopCatalog.java |  8 +++++++-
 .../java/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 b49d860fb..573cf42a0 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 class CommonUnifiedCatalog implements 
UnifiedCatalog {
 
   @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 class CommonUnifiedCatalog implements UnifiedCatalog 
{
 
   @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,
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 b50f0b12f..25d436a68 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 @@ package org.apache.amoro.formats.hudi;
 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 class HudiHadoopCatalog implements FormatCatalog {
         () -> {
           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 4ed6a9ea6..660293c47 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 @@ package org.apache.amoro.formats.mixed;
 
 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 class MixedCatalog implements FormatCatalog {
 
   @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

Reply via email to