Skip to content

Commit

Permalink
fix: update all namespace properties in update_namespace_properties (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ranli authored Jul 4, 2024
1 parent 19a2401 commit 473d28d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,16 @@ def update_namespace_properties(
IcebergNamespaceProperties.property_key.in_(set(updates.keys())),
)
session.execute(delete_stmt)
insert_stmt = insert(IcebergNamespaceProperties)
for property_key, property_value in updates.items():
insert_stmt = insert_stmt.values(
catalog_name=self.name, namespace=namespace_str, property_key=property_key, property_value=property_value
)
insert_stmt_values = [
{
IcebergNamespaceProperties.catalog_name: self.name,
IcebergNamespaceProperties.namespace: namespace_str,
IcebergNamespaceProperties.property_key: property_key,
IcebergNamespaceProperties.property_value: property_value,
}
for property_key, property_value in updates.items()
]
insert_stmt = insert(IcebergNamespaceProperties).values(insert_stmt_values)
session.execute(insert_stmt)
session.commit()
return properties_update_summary
7 changes: 6 additions & 1 deletion tests/catalog/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,12 @@ def test_update_namespace_properties(catalog: SqlCatalog, namespace: str) -> Non
assert k in update_report.missing
else:
assert k in update_report.removed
assert "updated test description" == catalog.load_namespace_properties(namespace)["comment"]
assert catalog.load_namespace_properties(namespace) == {
"comment": "updated test description",
"test_property4": "4",
"test_property5": "5",
"location": f"{warehouse_location}/{namespace}.db",
}


@pytest.mark.parametrize(
Expand Down

0 comments on commit 473d28d

Please sign in to comment.