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_r362062571
 
 

 ##########
 File path: api/src/main/java/org/apache/iceberg/catalog/SupportsNamespaces.java
 ##########
 @@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.catalog;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+
+/**
+ * Catalog methods for working with namespaces.
+ * <p>
+ * If an object such as a table, view, or function exists, its parent 
namespaces must also exist
+ * and must be returned by the discovery methods {@link #listNamespaces()} and
+ * {@link #listNamespaces(Namespace namespace)}.
+ * <p>
+ * Catalog implementations are not required to maintain the existence of 
namespaces independent of
+ * objects in a namespace. For example, a function catalog that loads 
functions using reflection
+ * and uses Java packages as namespaces is not required to support the methods 
to create, alter, or
+ * drop a namespace. Implementations are allowed to discover the existence of 
objects or namespaces
+ * without throwing {@link NoSuchNamespaceException} when no namespace is 
found.
+ */
+public interface SupportsNamespaces {
+  /**
+   * Create a namespace in the catalog.
+   *
+   * @param namespace {@link Namespace}.
+   * @throws AlreadyExistsException If the namespace already exists
+   * @throws UnsupportedOperationException If create is not a supported 
operation
+   */
+  default void createNamespace(Namespace namespace) {
+    createNamespace(namespace, ImmutableMap.of());
+  }
+
+  /**
+   * Create a namespace in the catalog.
+   *
+   * @param namespace a multi-part namespace
+   * @param metadata a string ImmutableMap of properties for the given 
namespace
+   * @throws AlreadyExistsException If the namespace already exists
+   * @throws UnsupportedOperationException If create is not a supported 
operation
+   */
+  void createNamespace(Namespace namespace, ImmutableMap<String, String> 
metadata);
+
+  /**
+   * List top-level namespaces from the catalog.
+   * <p>
+   * If an object such as a table, view, or function exists, its parent 
namespaces must also exist
+   * and must be returned by this discovery method. For example, if table 
a.b.t exists, this method
+   * must return ["a"] in the result array.
+   *
+   * @return an List of namespace {@link Namespace} names
+   */
+  default List<Namespace> listNamespaces() {
+    return listNamespaces(Namespace.empty());
+  }
+
+  /**
+   * List  namespaces from the namespace.
+   * <p>
+   * For example, if table a.b.t exists, use 'SELECT NAMESPACE IN a' this 
method
+   * must return Namepace.of("a","b") {@link Namespace}.
+   *
+   * @return an List of namespace {@link Namespace} names
+   * @throws NoSuchNamespaceException If the namespace does not exist 
(optional)
+   */
+  List<Namespace> listNamespaces(Namespace namespace) throws 
NoSuchNamespaceException;
+
+  /**
+   * Load metadata properties for a namespace.
+   *
+   * @param namespace a Namespace.of(name) {@link Namespace}
+   * @return a string map of properties for the given namespace
+   * @throws NoSuchNamespaceException If the namespace does not exist 
(optional)
+   */
+  Map<String, String> loadNamespaceMetadata(Namespace namespace) throws 
NoSuchNamespaceException;
+
+  /**
+   * Drop namespace, while the namespace haven't table or sub namespace will 
return true.
+   *
+   * @param namespace a Namespace.of(name) {@link Namespace}
+   * @return true while drop success.
+   * @throws NoSuchNamespaceException If the namespace does not exist 
(optional)
+   */
+  boolean dropNamespace(Namespace namespace) throws NoSuchNamespaceException;
+
+  /**
+   * Create a namespace in the catalog.
+   *
+   * @param namespace a multi-part namespace
+   * @param metadata a string ImmutableMap of properties for the given 
namespace
+   * @throws UnsupportedOperationException If create is not a supported 
operation
+   */
+  boolean alterNamespace(Namespace namespace, ImmutableMap<String, String> 
metadata);
 
 Review comment:
   Looks like you changed the method name from `setNamespaceMetadata` to 
`alterNamespace`, but that doesn't fix the problem I pointed out. I pointed out 
that the implementation was preserving properties instead of replacing the old 
set with the new map.
   
   The reason for that behavior -- and the method name that describes it -- is 
to make the expected result clear and to make it possible to edit the set of 
properties. For example, if I call `alterNamespace("db", Map("a" -> "1", "c" -> 
"3"))` and the namespace properties are `Map("a" -> "x", "b" -> "y")` then what 
happens to `"b"`? Should it be removed or left unchanged? If it should not be 
changed, then how does the caller remove a property? The name 
`setNamespaceMetadata` or a better one, `replaceNamespaceMetadata`, makes it 
clear that the entire set of properties is being replaced.
   
   There are a couple of alternatives to replacing the entire set of namespace 
metadata that are easier for the caller. The one I prefer is to mirror Spark's 
API and expose `alterNamespace(Namespace, NamespaceChange...)` where 
`NamespaceChange` can be `SetProperty` or `RemoveProperty`. That would look 
like this, with factory methods for the changes:
   
   ```java
   catalog.alterNamespace(ns, setProperty("a", "1"), removeProperty("b"));
   ```

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