rdblue commented on a change in pull request #688: [ISSUE #672] Add
SupportsNamespaces for 'HadoopCatalog' and 'HiveCatalog'
URL: https://github.com/apache/incubator-iceberg/pull/688#discussion_r360487986
##########
File path: hive/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
##########
@@ -163,6 +171,105 @@ public void renameTable(TableIdentifier from,
TableIdentifier to) {
}
}
+ @Override
+ public void createNamespace(Namespace namespace, Map<String, String> meta) {
+ Preconditions.checkArgument(!namespace.isEmpty(),
+ "Cannot create namespace with invalid name: %s", namespace.toString());
+ Preconditions.checkArgument(namespace.levels().length == 1,
+ "Cannot support multi part namespace in Hive MetaStore: %s",
namespace.toString());
+ try {
+ clients.run(client -> {
+ client.createDatabase(nameSpaceToHiveDb(namespace, meta));
+ return null;
+ });
+
+ } catch (AlreadyExistsException e) {
+ throw new
org.apache.iceberg.exceptions.AlreadyExistsException("Namespace %s already
exists:",
+ namespace.toString(), e.getMessage());
+
+ } catch (TException e) {
+ throw new RuntimeException("Failed to create namespace " +
namespace.toString() + " in Hive MataStore", e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted in call to createDatabase(name)"
+ namespace.toString(), e);
+ }
+ }
+
+ @Override
+ public List<Namespace> listNamespaces(Namespace namespace) {
+ if (!namespace.isEmpty() && namespace.levels().length != 1) {
+ throw new NoSuchNamespaceException("namespace does not exist: " +
namespace.toString());
+ }
+ List<Namespace> namespaces = new ArrayList<>();
+ List<String> dbs;
+ try {
+ dbs = namespace.isEmpty() ?
clients.run(HiveMetaStoreClient::getAllDatabases) :
+ clients.run(client -> client.getDatabases(namespace.level(0)));
+ for (String db : dbs) {
+ namespaces.add(Namespace.of(db));
+ }
+
+ return namespaces;
+
+ } catch (TException e) {
+ throw new RuntimeException("Failed to list all namespace: " +
namespace.toString(), e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted in call to getAllDatabases()" +
namespace.toString(), e);
+ }
+ }
+
+ @Override
+ public boolean dropNamespace(Namespace namespace, boolean cascade) {
+ if (namespace.isEmpty() || namespace.levels().length != 1) {
+ throw new NoSuchNamespaceException("namespace does not exist: " +
namespace.toString());
+ }
+ try {
+ clients.run(client -> {
+ client.dropDatabase(namespace.level(0), false, false, cascade);
+ return null;
+ });
+
+ return true;
+
+ } catch (NoSuchObjectException e) {
+ throw new NoSuchNamespaceException("namespace does not exist: " +
namespace.toString(), e.getMessage());
+
+ } catch (TException e) {
+ throw new RuntimeException("Failed to drop namespace " +
namespace.toString(), e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted in call to drop
dropDatabase(name)" + namespace.toString(), e);
+ }
+ }
+
+ @Override
+ public Map<String, String> loadNamespaceMetadata(Namespace namespace) {
+ if (namespace.isEmpty() || namespace.levels().length != 1) {
+ throw new NoSuchNamespaceException("namespace does not exist: " +
namespace.toString());
+ }
+ try {
Review comment:
Please add a newline above this.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]