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
5 changes: 5 additions & 0 deletions pyiceberg/table/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ def _(update: SetPropertiesUpdate, base_metadata: TableMetadata, context: _Table
properties = dict(base_metadata.properties)
properties.update(update.updates)

if properties == base_metadata.properties:
# Every key already has the requested value, so there is no change to record. Recording the
# update anyway would bump last_updated_ms and defeat the catalogs' skip-commit check.
return base_metadata

context.add_update(update)
return base_metadata.model_copy(update={"properties": properties})

Expand Down
17 changes: 17 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,23 @@ def test_remove_properties_already_removed_by_concurrent_commit(
assert catalog.load_table(test_table_identifier).properties == {}


def test_set_unchanged_properties_writes_no_new_metadata(
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"})

metadata_location = table.metadata_location
table.transaction().set_properties(a="1").commit_transaction()

loaded = catalog.load_table(test_table_identifier)
assert loaded.properties["a"] == "1"
# The value is already set, so the staged metadata equals the current metadata and the
# catalog must skip the commit instead of writing a metadata version that changes nothing
assert loaded.metadata_location == metadata_location


# Append table


Expand Down
21 changes: 21 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,27 @@ def test_apply_set_properties_update(table_v2: Table) -> None:
assert new_metadata_add_only.last_updated_ms > base_metadata.last_updated_ms


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

# The property already has this value, so nothing changes and nothing is recorded
unchanged = update_table_metadata(base_metadata, (SetPropertiesUpdate(updates={"read.split.target.size": "134217728"}),))
assert unchanged == base_metadata

# A new key, or a new value for an existing key, is a real change
added = update_table_metadata(base_metadata, (SetPropertiesUpdate(updates={"test_a": "test_a"}),))
assert added.properties == {"read.split.target.size": "134217728", "test_a": "test_a"}

changed = update_table_metadata(base_metadata, (SetPropertiesUpdate(updates={"read.split.target.size": "1"}),))
assert changed.properties == {"read.split.target.size": "1"}

# Mixed: one unchanged key and one new key still commits both
mixed = update_table_metadata(
base_metadata, (SetPropertiesUpdate(updates={"read.split.target.size": "134217728", "test_b": "test_b"}),)
)
assert mixed.properties == {"read.split.target.size": "134217728", "test_b": "test_b"}


@pytest.mark.parametrize("table_fixture", ["table_v1", "table_v2"])
@pytest.mark.parametrize("property_name", ["encryption.key-id", "encryption.data-key-length"])
def test_apply_set_properties_update_rejects_encryption_before_v3(
Expand Down
Loading