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_r360474730
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
 ##########
 @@ -195,8 +203,141 @@ 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(Namespace namespace) {
+    Preconditions.checkArgument(!namespace.isEmpty(), "Your Namespace must be 
not empty!");
+    List<Namespace> namespaces = new ArrayList<>();
+    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.
+          Namespace nsp = Namespace.of((namespace.toString() + "." + 
path.getName()).split("\\."));
+          namespaces.add(nsp);
+        }
+      }
+    } catch (IOException ioe) {
+      throw new RuntimeException("Failed to list namespace under " + 
namespace, ioe);
+    }
+
+    return namespaces;
+  }
+
+  @Override
+  public List<Namespace> listNamespaces() {
+    List<Namespace> namespaces = new ArrayList<>();
+    Path nsPath = new Path(warehouseLocation);
+    FileSystem fs = Util.getFs(nsPath, conf);
+    try {
+      if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) {
+        throw new NotFoundException("Unknown path " + nsPath);
+      }
+
+      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.
+          Namespace nsp = Namespace.of(path.getName());
+          namespaces.add(nsp);
+        }
+      }
+    } catch (IOException ioe) {
+      throw new RuntimeException("Failed to list namespace under " + nsPath, 
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) {
+    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())));
+    Map<String, String> meta = new HashMap<>();
+    FileSystem fs = Util.getFs(nsPath, conf);
+    try {
+      if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) {
+        throw new NotFoundException("Unknown namespace " + nsPath);
+      }
+      FileStatus info = fs.getFileStatus(nsPath);
+      meta.put("owner", info.getOwner());
+      meta.put("group", info.getGroup());
+      meta.put("path", info.getPath().toString());
+      meta.put("modification_time", Long.toString(info.getModificationTime()));
+      meta.put("block_size", Long.toString(info.getBlockSize()));
 
 Review comment:
   Please remove this metadata.

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