singhpk234 commented on code in PR #16096:
URL: https://github.com/apache/iceberg/pull/16096#discussion_r3140643335
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:
##########
@@ -483,6 +483,18 @@ public void alterNamespace(String[] namespace,
NamespaceChange... changes)
@Override
public boolean dropNamespace(String[] namespace, boolean cascade)
throws NoSuchNamespaceException {
+ if (cascade) {
+ for (String[] ns : listNamespaces(namespace)) {
+ dropNamespace(ns, true);
+ }
Review Comment:
shouldn't we drop all the namespaces last ?
##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -155,6 +155,35 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
+ @TestTemplate
+ public void testDropNamespaceCascade() {
+ assumeThat(catalogName).as("Session catalog has flaky
behavior").isNotEqualTo("spark_catalog");
+ assumeThat(catalogName).as("Multi part namespace is
unsupported").isNotEqualTo("testhive");
Review Comment:
can we have coverage for just non-nested namespace then for this ?
##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -155,6 +155,35 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
+ @TestTemplate
+ public void testDropNamespaceCascade() {
+ assumeThat(catalogName).as("Session catalog has flaky
behavior").isNotEqualTo("spark_catalog");
+ assumeThat(catalogName).as("Multi part namespace is
unsupported").isNotEqualTo("testhive");
+
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
+
+ sql("CREATE NAMESPACE %s", fullNamespace);
+ sql("CREATE NAMESPACE %s.nested", fullNamespace);
+ sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
+ sql("CREATE TABLE %s.nested.table (id bigint) USING iceberg",
fullNamespace);
+
+ Namespace nestedNs = Namespace.of("db", "nested");
+
+ assertThat(validationNamespaceCatalog.namespaceExists(NS)).isTrue();
+ assertThat(validationNamespaceCatalog.namespaceExists(nestedNs)).isTrue();
+ assertThat(validationCatalog.tableExists(TableIdentifier.of(NS,
"table"))).isTrue();
+ assertThat(validationCatalog.tableExists(TableIdentifier.of(nestedNs,
"table"))).isTrue();
Review Comment:
lets add a view too in both the namespace ?
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:
##########
@@ -483,6 +483,18 @@ public void alterNamespace(String[] namespace,
NamespaceChange... changes)
@Override
public boolean dropNamespace(String[] namespace, boolean cascade)
throws NoSuchNamespaceException {
+ if (cascade) {
+ for (String[] ns : listNamespaces(namespace)) {
+ dropNamespace(ns, true);
+ }
+ for (Identifier view : listViews(namespace)) {
+ dropView(view);
+ }
+ for (Identifier table : listTables(namespace)) {
+ dropTable(table);
+ }
Review Comment:
```suggestion
listNamespaces(namespace).forEach(n -> dropNamespace(n, true));
listViews(namespace).forEach(v -> dropView(v));
listTables(table).forEach(t -> dropTable(t));
```
--
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]