sagib1 commented on code in PR #16061:
URL: https://github.com/apache/iceberg/pull/16061#discussion_r3110646571


##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java:
##########
@@ -550,6 +550,13 @@ public boolean dropNamespace(Namespace namespace) throws 
NamespaceNotEmptyExcept
       }
     }
 
+    List<Namespace> childNamespaces = listNamespaces(namespace);
+    if (childNamespaces != null && !childNamespaces.isEmpty()) {
+      throw new NamespaceNotEmptyException(
+          "Namespace %s is not empty. Contains %d child namespace(s).",
+          namespace, childNamespaces.size());
+    }

Review Comment:
   Yes, I reviewed the other _SupportsNamespaces_ implementations. This issue 
is unique to JdbcCatalog because it must manually emulate hierarchical path 
validation over a flat SQL table.
   
   Other catalogs avoid this because they defer the drop operation to backends 
that enforce these constraints natively, or they structurally cannot support 
nested namespaces:
   
   **HadoopCatalog**: In its 
[dropNamespace](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java#L335)
 implementation, it calls `fs.delete(dir, false)`. By passing false for the 
recursive flag, it relies on the native Hadoop FileSystem to throw an 
`IOException` if any child directories (which represent sub-namespaces or 
tables) exist.
   
   **HiveCatalog**: Its 
[dropNamespace](https://github.com/apache/iceberg/blob/main/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L543)
 method delegates to HMS via `client.dropDatabase(name, false, false, false)` 
(where the final flag is cascade=false). The Hive Metastore natively throws an 
exception if the database is not empty. Furthermore, HMS structurally does not 
support nested namespaces.
   
   **GlueCatalog**: AWS Glue only supports top-level databases. Iceberg's 
[IcebergToGlueConverter.toDatabaseName](https://github.com/apache/iceberg/blob/main/aws/src/main/java/org/apache/iceberg/aws/glue/IcebergToGlueConverter.java#L123)
 enforces this by throwing a `ValidationException` if the namespace has more 
than 1 level, making this specific nested-drop edge case impossible.
   
   **NessieCatalog**: Defers entirely to the Nessie API via 
[api.deleteNamespace()](https://github.com/apache/iceberg/blob/main/nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java#L321).
 the logic simply sends a delete() request to the remote Nessie Server. Because 
Nessie is essentially "Git for Data," the Nessie server itself maintains the 
entire hierarchical tree of commits and references. When the server receives 
the delete request, its internal engine traverses the commit tree. If it finds 
any active keys (whether they are tables, views, or child namespaces) under 
that path, the server rejects the request and throws a 
`NessieNamespaceNotEmptyException` back over the wire.



##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalog.java:
##########
@@ -859,6 +859,25 @@ public void testDropNamespace() {
         .hasMessage("Namespace db is not empty. Contains 1 table(s).");
   }
 
+  @Test
+  public void testDropNamespaceWithChildNamespace() {
+    Namespace parent = Namespace.of("parent_ns");
+    Namespace child = Namespace.of("parent_ns", "child_ns");
+
+    // 1. Create the parent and child namespaces
+    catalog.createNamespace(parent);
+    catalog.createNamespace(child);
+
+    // 2. Assert that dropping the parent fails because the child exists
+    assertThatThrownBy(() -> catalog.dropNamespace(parent))
+        .isInstanceOf(NamespaceNotEmptyException.class)
+        .hasMessageStartingWith("Namespace parent_ns is not empty. Contains 1 
child namespace(s).");
+
+    // 3. Verify the namespaces still safely exist in the catalog

Review Comment:
   agreed, removed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to