XiaokunDing commented on a change in pull request #919: [ISSUE #672] Add 
SupportsNamespaces on HiveCatalog and HadoopCatalog
URL: https://github.com/apache/incubator-iceberg/pull/919#discussion_r407873635
 
 

 ##########
 File path: hive/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
 ##########
 @@ -155,14 +164,146 @@ public void renameTable(TableIdentifier from, 
TableIdentifier to) {
       throw new org.apache.iceberg.exceptions.AlreadyExistsException("Table 
already exists: %s", to);
 
     } catch (TException e) {
-      throw new RuntimeException("Failed to rename " + from.toString() + " to 
" + to.toString(), e);
+      throw new RuntimeException("Failed to rename " + from + " to " + to, e);
 
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       throw new RuntimeException("Interrupted in call to rename", e);
     }
   }
 
+  @Override
+  public void createNamespace(Namespace namespace, ImmutableMap<String, 
String> meta) {
+    Preconditions.checkArgument(
+        !namespace.isEmpty(),
+        "Cannot create namespace with invalid name: %s", namespace);
+    Preconditions.checkArgument(
+        namespace.levels().length == 1,
+        "Cannot support multi part namespace in Hive MetaStore: %s", 
namespace);
+
+    try {
+      clients.run(client -> {
+        client.createDatabase(convertToDatabase(namespace, meta));
+        return null;
+      });
+
+    } catch (AlreadyExistsException e) {
+      throw new org.apache.iceberg.exceptions.AlreadyExistsException(e, 
"Namespace '%s' already exists!",
+            namespace);
+
+    } catch (TException e) {
+      throw new RuntimeException("Failed to create namespace " + namespace + " 
in Hive MataStore", e);
+
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(
+          "Interrupted in call to createDatabase(name) " + namespace + " in 
Hive MataStore", e);
+    }
+  }
+
+  @Override
+  public List<Namespace> listNamespaces(Namespace namespace) {
+    if (namespace.levels().length > 1) {
+      throw new NoSuchNamespaceException("Namespace does not exist: %s", 
namespace);
+    }
+    if (!namespace.isEmpty()) {
+      return ImmutableList.of();
+    }
+    try {
+      return clients.run(
+          HiveMetaStoreClient::getAllDatabases)
+          .stream()
+          .map(Namespace::of)
+          .collect(Collectors.toList());
+
+    } catch (TException e) {
+      throw new RuntimeException("Failed to list all namespace: " + namespace 
+ " in Hive MataStore",  e);
+
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(
+          "Interrupted in call to getAllDatabases() " + namespace + " in Hive 
MataStore", e);
+    }
+  }
+
+  @Override
+  public boolean dropNamespace(Namespace namespace) {
+    if (namespace.levels().length != 1) {
+      throw new NoSuchNamespaceException("Namespace does not exist: %s", 
namespace);
+    }
+
+    try {
+      clients.run(client -> {
+        client.dropDatabase(namespace.level(0),
+            false /* deleteData */,
+            false /* ignoreUnknownDb */,
+            true /* cascade */);
 
 Review comment:
   OK I fixed it delete data together at here, I was think delete data is a 
danger operation.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to