Skip to content
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
3 changes: 2 additions & 1 deletion pyiceberg/table/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ def _(update: RemovePropertiesUpdate, base_metadata: TableMetadata, context: _Ta

properties = dict(base_metadata.properties)
for key in update.removals:
properties.pop(key)
# Ignore keys that aren't set, since a concurrent commit may have removed them
Comment thread
smaheshwar-pltr marked this conversation as resolved.
Resolved
properties.pop(key, None)

context.add_update(update)
return base_metadata.model_copy(update={"properties": properties})
Expand Down
14 changes: 14 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,20 @@ def test_table_properties_raise_for_none_value(
assert "None type is not a supported value in properties: property_name" in str(exc_info.value)


def test_remove_properties_already_removed_by_concurrent_commit(
catalog: Catalog, table_schema_simple: Schema, test_table_identifier: Identifier
) -> None:
namespace = Catalog.namespace_from(test_table_identifier)
catalog.create_namespace(namespace)
table = catalog.create_table(test_table_identifier, table_schema_simple, properties={"a": "1", "b": "2"})

transaction = table.transaction().remove_properties("a", "b")
catalog.load_table(test_table_identifier).transaction().remove_properties("a").commit_transaction()
transaction.commit_transaction()

assert catalog.load_table(test_table_identifier).properties == {}


# Append table


Expand Down
9 changes: 4 additions & 5 deletions tests/integration/test_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_hive_critical_properties_always_from_iceberg(catalog: Catalog) -> None:
def test_hive_native_properties_cannot_be_deleted_via_iceberg(catalog: Catalog) -> None:
"""Test that HMS-native properties (set outside Iceberg) cannot be deleted via Iceberg.

HMS-native properties are not visible to Iceberg, so remove_properties fails with KeyError.
HMS-native properties are not visible to Iceberg, so remove_properties leaves them in place.
However, if you first SET an HMS property via Iceberg (making it tracked in Iceberg metadata),
it can then be deleted via Iceberg.
"""
Expand All @@ -326,16 +326,15 @@ def test_hive_native_properties_cannot_be_deleted_via_iceberg(catalog: Catalog)
# Verify the HMS-native property is NOT visible in Iceberg
assert "hms_native_prop" not in table.properties

# Attempt to remove the HMS-native property via Iceberg - this should fail
# Removing the HMS-native property via Iceberg leaves it in place,
# because the property is not tracked in Iceberg metadata (not visible to Iceberg)
with pytest.raises(KeyError):
table.transaction().remove_properties("hms_native_prop").commit_transaction()
table.transaction().remove_properties("hms_native_prop").commit_transaction()

# HMS-native property should still exist (cannot be deleted via Iceberg)
with hive_client as open_client:
hive_table = _get_hive_table(open_client)
assert hive_table.parameters.get("hms_native_prop") == "native_value", (
"HMS-native property should still exist since Iceberg removal failed!"
"HMS-native property should still exist since Iceberg doesn't track it!"
)

# Now SET the same property via Iceberg (this makes it tracked in Iceberg metadata)
Expand Down
15 changes: 15 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,21 @@ def test_apply_remove_properties_update(table_v2: Table) -> None:
assert new_metadata.properties == {"read.split.target.size": "134217728", "test_b": "test_b", "test_d": "test_d"}


def test_apply_remove_properties_update_ignores_unset_keys(table_v2: Table) -> None:
base_metadata = table_v2.metadata

new_metadata_no_removal = update_table_metadata(base_metadata, (RemovePropertiesUpdate(removals=["test_a"]),))

assert new_metadata_no_removal.properties == base_metadata.properties
assert new_metadata_no_removal.last_updated_ms > base_metadata.last_updated_ms

new_metadata = update_table_metadata(base_metadata, (RemovePropertiesUpdate(removals=["read.split.target.size", "test_a"]),))

assert base_metadata.properties == {"read.split.target.size": "134217728"}
assert new_metadata.properties == {}
assert new_metadata.last_updated_ms > base_metadata.last_updated_ms


def test_apply_add_schema_update(table_v2: Table) -> None:
transaction = table_v2.transaction()
update = transaction.update_schema()
Expand Down