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
16 changes: 14 additions & 2 deletions pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,9 @@ def update_namespace_properties(
raise NoSuchNamespaceError(f"Namespace {namespace_str} does not exists")

current_properties = self.load_namespace_properties(namespace=namespace)
properties_update_summary = self._get_updated_props_and_update_summary(
properties_update_summary, updated_properties = self._get_updated_props_and_update_summary(
current_properties=current_properties, removals=removals, updates=updates
)[0]
)

with Session(self.engine) as session:
if removals:
Expand Down Expand Up @@ -815,6 +815,18 @@ def update_namespace_properties(
]
insert_stmt = insert(IcebergNamespaceProperties).values(insert_stmt_values)
session.execute(insert_stmt)

if properties_update_summary.removed and not updated_properties:
# A namespace without tables only exists through its properties
for key, value in IcebergNamespaceProperties.NAMESPACE_MINIMAL_PROPERTIES.items():
session.add(
IcebergNamespaceProperties(
catalog_name=self.name,
namespace=namespace_str,
property_key=key,
property_value=value,
)
)
session.commit()
return properties_update_summary

Expand Down
9 changes: 9 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,15 @@ def test_update_namespace_properties(catalog: Catalog, test_namespace: Identifie
}


def test_update_namespace_properties_removes_all_properties(catalog: Catalog, test_namespace: Identifier) -> None:
catalog.create_namespace(test_namespace, {"comment": "this is a test description"})
update_report = catalog.update_namespace_properties(test_namespace, removals={"comment"})
assert update_report.removed == ["comment"]
assert catalog.namespace_exists(test_namespace)
assert test_namespace in catalog.list_namespaces(test_namespace[:-1])
assert catalog.load_namespace_properties(test_namespace) == {"exists": "true"}


def test_update_namespace_metadata_raises_error_when_namespace_does_not_exist(
catalog: Catalog, test_namespace: Identifier, test_table_properties: dict[str, str]
) -> None:
Expand Down