Skip to content

Spark: Add support for CASCADE option in DROP NAMESPACE - #16096

Open
ebyhr wants to merge 2 commits into
apache:mainfrom
ebyhr:ebi/spark-drop-namespace-cascade
Open

Spark: Add support for CASCADE option in DROP NAMESPACE#16096
ebyhr wants to merge 2 commits into
apache:mainfrom
ebyhr:ebi/spark-drop-namespace-cascade

Conversation

@ebyhr

@ebyhr ebyhr commented Apr 24, 2026

Copy link
Copy Markdown
Member

Summary

Add support for the CASCADE option in DROP NAMESPACE statements in Spark 4.1.
When CASCADE is specified, the operation recursively drops all nested namespaces, tables,
and views within the target namespace before dropping the namespace itself.

Implementation

  • Modified SparkCatalog and SparkSessionCatalog to handle the cascade parameter
  • When cascade=true, the implementation:
    • Recursively drops all nested namespaces
    • Drops all tables in the namespace
    • Drops all views in the namespace
    • Finally drops the namespace itself

@github-actions github-actions Bot added the spark label Apr 24, 2026
@ebyhr
ebyhr force-pushed the ebi/spark-drop-namespace-cascade branch from ab6aaa4 to c33ef20 Compare April 24, 2026 07:08
@ebyhr
ebyhr marked this pull request as draft April 24, 2026 07:09
@ebyhr
ebyhr force-pushed the ebi/spark-drop-namespace-cascade branch from c33ef20 to c4de5a8 Compare April 24, 2026 07:18
@ebyhr
ebyhr marked this pull request as ready for review April 24, 2026 09:15
Comment on lines +487 to +489
for (String[] ns : listNamespaces(namespace)) {
dropNamespace(ns, true);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we drop all the namespaces last ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean views → tables → nested views → nested tables → all namespaces?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singhpk234 I'm wondering whether this is really worth doing, since it requires additional logic. Could you explain the motivation for dropping namespaces last?

@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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have coverage for just non-nested namespace then for this ?

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add a view too in both the namespace ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadoop catalog doesn't support views. That is why I updated TestViews. Left a code comment.

Comment on lines +487 to +495
for (String[] ns : listNamespaces(namespace)) {
dropNamespace(ns, true);
}
for (Identifier view : listViews(namespace)) {
dropView(view);
}
for (Identifier table : listTables(namespace)) {
dropTable(table);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (String[] ns : listNamespaces(namespace)) {
dropNamespace(ns, true);
}
for (Identifier view : listViews(namespace)) {
dropView(view);
}
for (Identifier table : listTables(namespace)) {
dropTable(table);
}
listNamespaces(namespace).forEach(n -> dropNamespace(n, true));
listViews(namespace).forEach(v -> dropView(v));
listTables(table).forEach(t -> dropTable(t));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those methods return arrays. I updated views / tables lines with Arrays.stream. Skipped namespace line because the method throws NoSuchNamespaceException which requires additional try-catch.

@ebyhr

ebyhr commented May 1, 2026

Copy link
Copy Markdown
Member Author

Addressed comments except for #16096 (comment)

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jun 1, 2026
@ebyhr

ebyhr commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@singhpk234 could you take another look when you have time?

@github-actions github-actions Bot removed the stale label Jun 2, 2026
@ebyhr
ebyhr requested a review from singhpk234 June 28, 2026 22:05
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 29, 2026
@ebyhr
ebyhr force-pushed the ebi/spark-drop-namespace-cascade branch from 7e4e7cb to 18561ff Compare July 29, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants