Skip to content

Reject dropping a SqlCatalog namespace that has child namespaces - #4469

Open
gedaliakliger wants to merge 1 commit into
apache:mainfrom
gedaliakliger:fix/sql-drop-namespace-with-children
Open

gedaliakliger wants to merge 1 commit into
apache:mainfrom
gedaliakliger:fix/sql-drop-namespace-with-children

Conversation

@gedaliakliger

Copy link
Copy Markdown
Contributor

Rationale for this change

SqlCatalog.drop_namespace only checks for tables. With namespaces a and a.b, drop_namespace("a") deletes the properties of a and returns, while a is still listed and still exists through its child. InMemoryCatalog inherits this.

Java's JdbcCatalog.dropNamespace throws NamespaceNotEmptyException when listNamespaces(namespace) is not empty. This change does the same and raises NamespaceNotEmptyError.

Are these changes tested?

Yes. test_drop_namespace_raises_error_when_namespace_has_child_namespaces fails on main (DID NOT RAISE NamespaceNotEmptyError) and passes with this change. Ran here: the namespace tests in tests/catalog/test_catalog_behaviors.py, tests/catalog/test_sql.py and tests/cli/test_console.py (258 passed), plus ruff, ruff-format and mypy on the changed files. The full suites are left to CI.

Are there any user-facing changes?

Yes. drop_namespace on SqlCatalog and InMemoryCatalog raises NamespaceNotEmptyError for a namespace that has child namespaces, instead of returning without dropping it.

drop_namespace only checked for tables, so dropping a parent namespace
deleted its properties and reported success while its children kept it
listed. Java's JdbcCatalog.dropNamespace throws NamespaceNotEmptyException
in this case.

@rahulsmahadev rahulsmahadev left a comment

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.

Thanks @gedaliakliger! The new test fails on main ("DID NOT RAISE") and passes here, and checking child namespaces before tables matches Java's JdbcCatalog.dropNamespace. I also tried a sibling that shares a prefix (p and pq), an underscore name (a_b and axb), a grandchild, a table in a sibling, and a child that exists only as properties. Each behaved as expected, and a failed drop leaves the properties alone.

Optional: add a sibling case to the new test. list_namespaces relies on an exact tuple check after a LIKE query, and a later change there could break this without any test noticing. And because this turns a silent no-op into an exception, the answer to "user-facing changes" could ask for the changelog label.

@gedaliakliger

Copy link
Copy Markdown
Contributor Author

Thanks for checking this. test_list_namespaces_fuzzy_match already verifies that listing db.ns1 excludes db.ns1X.ns3, so I kept the drop test focused on child namespaces. Please add the changelog label: dropping a parent with children now raises NamespaceNotEmptyError instead of returning successfully.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants