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_r361726693
##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
##########
@@ -200,7 +211,110 @@ public void renameTable(TableIdentifier from,
TableIdentifier to) {
}
@Override
- public void close() throws IOException {
+ public void createNamespace(Namespace namespace, Map<String, String> meta) {
+ Preconditions.checkArgument(!namespace.isEmpty(),
+ "Cannot create namespace with invalid name: %s", namespace);
+ if (meta.size() > 0) {
+ LOG.warn("Hadoop Catalog not support metadata {} on namespace: {}",
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
org.apache.iceberg.exceptions.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) {
+ List<Namespace> namespaceList = new ArrayList<>();
+ String[] namespaces;
+ 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 NoSuchNamespaceException("Namespace does not exist: %s",
namespace);
+ }
+
+ List<String> pathList =
Stream.of(fs.listStatus(nsPath)).map(FileStatus::getPath)
+ .filter(path -> isNamespace(fs,
path)).map(Path::getName).collect(Collectors.toList());
+
+ for (String path : pathList) {
+ if (!namespace.isEmpty()) {
+ namespaces = Namespace.of(namespace.toString() + "." +
path).levels();
+ } else {
+ namespaces = new String[]{path};
+ }
+ namespaceList.add(Namespace.of(namespaces));
+ }
+ } catch (IOException ioe) {
+ throw new RuntimeIOException(ioe, "Failed to list namespace under: %s",
namespace);
+ }
+
+ return namespaceList;
+ }
+
+ @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 org.apache.iceberg.exceptions.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 setNamespaceMetadata(Namespace namespace, Map<String, String>
meta) {
+ throw new UnsupportedOperationException(
+ "Unsupported setNamespaceMetadata() in the HadoopCatalog: " +
namespace.toString());
}
+ @Override
+ public Map<String, String> loadNamespaceMetadata(Namespace namespace) {
+ if (namespace.isEmpty()) {
+ throw new NoSuchNamespaceException("Namespace does not exist: %s",
namespace);
+ }
+
+ Path nsPath = new Path(SLASH.join(warehouseLocation,
SLASH.join(namespace.levels())));
Review comment:
The implementation here is confusing because it mixes two separate concerns:
checking whether the namespace exists and building namespace metadata. These
should be separate. Why not add a case to the check above that calls
`isNamespace`?
----------------------------------------------------------------
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]