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_r360477973
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
 ##########
 @@ -195,8 +203,108 @@ public void renameTable(TableIdentifier from, 
TableIdentifier to) {
     throw new UnsupportedOperationException("Cannot rename Hadoop tables");
   }
 
+  @Override
+  public boolean createNamespace(Namespace namespace) {
+    Preconditions.checkArgument(!namespace.isEmpty(), "Your Namespace must be 
not empty!");
+    Joiner slash = Joiner.on("/");
+    Path nsPath = new Path(slash.join(warehouseLocation, 
slash.join(namespace.levels())));
+    return io().mkdir(nsPath.toString());
+  }
+
+  @Override
+  public List<Namespace> listNamespaces() {
+    return listNamespaces(Namespace.empty());
+  }
+
+  @Override
+  public List<Namespace> listNamespaces(Namespace namespace) {
+ //   Preconditions.checkArgument(!namespace.isEmpty(), "Your Namespace must 
be not empty!");
+    List<Namespace> namespaces = new ArrayList<>();
+    String[] nsp;
+    Joiner slash = Joiner.on("/");
+    Path nsPath = new Path(slash.join(warehouseLocation, 
slash.join(namespace.levels())));
+    FileSystem fs = Util.getFs(nsPath, conf);
+    try {
+      if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) {
+        throw new NotFoundException("Unknown namespace " + namespace);
+      }
+
+      for (FileStatus s : fs.listStatus(nsPath)) {
+        Path path = s.getPath();
+        if (!fs.isDirectory(path)) {
+          // Ignore the path which is not a directory.
+          continue;
+        }
+        Path metadataPath = new Path(path, "metadata");
+        if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) &&
+            (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) {
+        // Ignore the path of table
+          continue;
+        }
+
+        if (fs.exists(path) && fs.isDirectory(path)) {
+          // Only the path which contains metadata is the path for table, 
otherwise it could be
+          // still a namespace.
+          if (!namespace.isEmpty()) {
+            nsp = (namespace.toString() + "." + path.getName()).split("\\.");
+          } else {
+            nsp = new String[] {path.getName()};
+          }
+          namespaces.add(Namespace.of(nsp));
+        }
+      }
+    } catch (IOException ioe) {
+      throw new RuntimeException("Failed to list namespace under " + 
namespace, ioe);
+    }
+
+    return namespaces;
+  }
+
+  @Override
+  public boolean dropNamespace(Namespace namespace) {
+    Preconditions.checkArgument(!namespace.isEmpty(), "Your Namespace must be 
not empty!");
+    Preconditions.checkArgument(listTables(namespace).size() == 0,
+        "This Namespace have tables, cannot drop it");
+    Preconditions.checkArgument(listNamespaces(namespace).size() == 0,
+        "This Namespace have sub Namespace, cannot drop it");
+
+    Joiner slash = Joiner.on("/");
+    Path nsPath = new Path(slash.join(warehouseLocation, 
slash.join(namespace.levels())));
+    io().deleteFile(nsPath.toString());
+    return true;
+  }
+
+  @Override
+  public Map<String, String> loadNamespaceMetadata(Namespace namespace) {
 
 Review comment:
   This can return an empty map for Hadoop tables, since there is no namespace 
metadata. I think it is also okay to return "location" with the namespace's 
path in the map.

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