snazy commented on code in PR #11215:
URL: https://github.com/apache/iceberg/pull/11215#discussion_r1777528160


##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -358,6 +360,57 @@ private static void checkNamespaceIsValid(Namespace 
namespace) {
     }
   }
 
+  /**
+   * Resolves the "location" for a new table or view, respecting the 
"location" property of the
+   * "nearest" namespace.
+   */
+  public String locationForNewEntity(TableIdentifier table, String 
warehouseLocation)
+      throws NoSuchNamespaceException {
+
+    String location = warehouseLocation;
+    if (table.hasNamespace()) {
+      Namespace namespace = table.namespace();
+      checkNamespaceIsValid(namespace);
+
+      List<String> keyElements = List.of(namespace.levels());
+      int keyElementCount = keyElements.size();
+
+      List<ContentKey> keysInOrder = 
Lists.newArrayListWithCapacity(keyElementCount);
+      for (int i = 0; i < keyElementCount; i++) {
+        ContentKey key = ContentKey.of(keyElements.subList(0, i + 1));
+        keysInOrder.add(key);
+      }
+
+      try {
+        Map<ContentKey, Content> contentMap =
+            withReference(api.getContent()).keys(keysInOrder).get();
+        int index;
+        for (index = keysInOrder.size() - 1; index >= 0; index--) {
+          ContentKey key = keysInOrder.get(index);
+          String namespaceLocation =
+              unwrapNamespace(contentMap.get(key))
+                  .map(org.projectnessie.model.Namespace::getProperties)
+                  .map(p -> p.get("location"))
+                  .orElse(null);
+          if (namespaceLocation != null) {
+            location = namespaceLocation;
+            break;
+          }
+        }
+        for (index++; index < keyElementCount; index++) {
+          location += "/" + keyElements.get(index);

Review Comment:
   Updated the PR description



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

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to