Skip to content

fix: glue drop_namespace to check non-iceberg tables #2083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged
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
14 changes: 10 additions & 4 deletions pyiceberg/catalog/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,19 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
"""
database_name = self.identifier_to_database(namespace, NoSuchNamespaceError)
try:
table_list = self.list_tables(namespace=database_name)
except NoSuchNamespaceError as e:
table_list_response = self.glue.get_tables(DatabaseName=database_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

table_list = table_list_response["TableList"]
except self.glue.exceptions.EntityNotFoundException as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

self.glue.exceptions.EntityNotFoundException mirrors the list_tables implementation

except self.glue.exceptions.EntityNotFoundException as e:
raise NoSuchNamespaceError(f"Database does not exist: {database_name}") from e

raise NoSuchNamespaceError(f"Database does not exist: {database_name}") from e

if len(table_list) > 0:
raise NamespaceNotEmptyError(f"Database {database_name} is not empty")

first_table = table_list[0]
if self.__is_iceberg_table(first_table):
raise NamespaceNotEmptyError(f"Cannot drop namespace {database_name} because it still contains Iceberg tables")
else:
raise NamespaceNotEmptyError(
f"Cannot drop namespace {database_name} because it still contains non-Iceberg tables"
)
self.glue.delete_database(Name=database_name)

def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
Expand Down
12 changes: 12 additions & 0 deletions tests/catalog/test_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,18 @@ def test_drop_non_empty_namespace(
test_catalog.drop_namespace(database_name)


@mock_aws
def test_drop_namespace_that_contains_non_iceberg_tables(
_bucket_initialize: None, moto_endpoint_url: str, table_schema_nested: Schema, database_name: str, table_name: str
) -> None:
test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"})
test_catalog.create_namespace(namespace=database_name)
test_catalog.glue.create_table(DatabaseName=database_name, TableInput={"Name": "hive_table"})

with pytest.raises(NamespaceNotEmptyError):
test_catalog.drop_namespace(database_name)


@mock_aws
def test_drop_non_exist_namespace(_bucket_initialize: None, moto_endpoint_url: str, database_name: str) -> None:
test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url})
Expand Down