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_r362058161
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
 ##########
 @@ -200,7 +211,108 @@ public void renameTable(TableIdentifier from, 
TableIdentifier to) {
   }
 
   @Override
-  public void close() throws IOException {
+  public void createNamespace(Namespace namespace, ImmutableMap<String, 
String> meta) {
+    Preconditions.checkArgument(
+        !namespace.isEmpty(),
+        "Cannot create namespace with invalid name: %s", namespace);
+    Preconditions.checkArgument(
+        meta.isEmpty(),
+        "Hadoop Catalog not support metadata %s on namespace: %s", meta, 
namespace);
+
+    Path nsPath = new Path(SLASH.join(warehouseLocation, 
SLASH.join(namespace.levels())));
+    FileSystem fs = Util.getFs(nsPath, conf);
+
+    try {
+      if (isNamespace(fs, nsPath)) {
+        throw new AlreadyExistsException("Namespace '%s' already exists!", 
namespace);
+      }
+
+      fs.mkdirs(nsPath);
+
+    } catch (IOException e) {
+      throw new RuntimeIOException(e, "Create namespace failed: %s", 
namespace);
+    }
+  }
+
+  @Override
+  public List<Namespace> listNamespaces(Namespace namespace) {
+    Path nsPath = new Path(SLASH.join(warehouseLocation, 
SLASH.join(namespace.levels())));
+    FileSystem fs = Util.getFs(nsPath, conf);
+
+    if (!isNamespace(fs, nsPath)) {
+      throw new NoSuchNamespaceException("Namespace does not exist: %s", 
namespace);
+    }
+
+    try {
+      if (!namespace.isEmpty()) {
+        return Stream.of(fs.listStatus(nsPath))
+            .map(FileStatus::getPath)
+            .filter(path -> isNamespace(fs, path))
+            .map(path -> Namespace.of(namespace.toString() + "." + 
path.getName()))
+            .collect(Collectors.toList());
+      } else {
+        return Stream.of(fs.listStatus(nsPath))
+            .map(FileStatus::getPath)
+            .filter(path -> isNamespace(fs, path))
+            .map(path -> Namespace.of(path.getName()))
+            .collect(Collectors.toList());
+      }
+
+    } catch (IOException ioe) {
+      throw new RuntimeIOException(ioe, "Failed to list namespace under: %s", 
namespace);
+    }
   }
 
+  @Override
+  public boolean dropNamespace(Namespace namespace) {
+    Path nsPath = new Path(SLASH.join(warehouseLocation, 
SLASH.join(namespace.levels())));
+    FileSystem fs = Util.getFs(nsPath, conf);
+
+    try {
+      if (!isNamespace(fs, nsPath)) {
+        throw new NoSuchNamespaceException("Namespace does not exist: %s", 
namespace);
+      }
+
+      return fs.delete(nsPath, true /* recursive */);
+
+    } catch (IOException e) {
+      throw new RuntimeIOException(e, "Namespace delete failed: %s", 
namespace);
+    }
+  }
+
+  @Override
+  public boolean alterNamespace(Namespace namespace, ImmutableMap<String, 
String> meta) {
+    throw new UnsupportedOperationException("Unsupported 
setNamespaceMetadata() in the HadoopCatalog: " + namespace);
 
 Review comment:
   This method was renamed to `alterNamespace`, so this error message is no 
longer correct.
   
   In general, this is why it is a bad idea to include method names in error 
messages. Instead, this should be more specific about what is not supported, 
not the method call that caused it. Like the create method, this should state 
"Namespace metadata is not supported".

----------------------------------------------------------------
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]

Reply via email to