Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
raise NoSuchNamespaceError(f"Namespace does not exist: {namespace}")

namespace_str = Catalog.namespace_to_string(namespace)
if child_namespaces := self.list_namespaces(namespace_str):
raise NamespaceNotEmptyError(f"Namespace {namespace_str} is not empty. {len(child_namespaces)} namespaces exist.")

if tables := self.list_tables(namespace):
raise NamespaceNotEmptyError(f"Namespace {namespace_str} is not empty. {len(tables)} tables exist.")

Expand Down
13 changes: 13 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,19 @@ def test_drop_namespace_raises_error_when_namespace_not_empty(
catalog.drop_namespace(namespace)


def test_drop_namespace_raises_error_when_namespace_has_child_namespaces(catalog: Catalog, test_namespace: Identifier) -> None:
child_namespace = test_namespace + ("child",)
catalog.create_namespace(test_namespace)
catalog.create_namespace(child_namespace)
with pytest.raises(NamespaceNotEmptyError, match=f"Namespace {'.'.join(test_namespace)} is not empty. 1 namespaces exist."):
catalog.drop_namespace(test_namespace)
assert catalog.namespace_exists(test_namespace)
assert catalog.namespace_exists(child_namespace)
catalog.drop_namespace(child_namespace)
catalog.drop_namespace(test_namespace)
assert not catalog.namespace_exists(test_namespace)


# RecordBatchReader streaming append/overwrite tests
#
# Streaming writes accept a pa.RecordBatchReader and microbatch it into target-sized
Expand Down
Loading