Fokko commented on code in PR #4522:
URL: https://github.com/apache/iceberg-python/pull/4522#discussion_r4738572422


##########
pyiceberg/table/update/__init__.py:
##########
@@ -373,12 +373,13 @@ def _(update: SetPropertiesUpdate, base_metadata: 
TableMetadata, context: _Table
 
 @_apply_table_update.register(RemovePropertiesUpdate)
 def _(update: RemovePropertiesUpdate, base_metadata: TableMetadata, context: 
_TableMetadataUpdateContext) -> TableMetadata:
-    if len(update.removals) == 0:
-        return base_metadata
-
     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
+        properties.pop(key, None)
+
+    if len(properties) == len(base_metadata.properties):
+        return base_metadata

Review Comment:
   Align with Java's 
[`TableMetadata.Builder.removeProperties`](https://github.com/apache/iceberg/blob/f0e7de3c2f207a49ac3a241ac7346726c08c8f1b/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1485-L1494),
 which records the change even if none of the keys are set:
   
   ```suggestion
       if len(update.removals) == 0:
           return base_metadata
   
       properties = dict(base_metadata.properties)
       for key in update.removals:
           # Ignore keys that aren't set, since a concurrent commit may have 
removed them
           properties.pop(key, None)
   ```



##########
tests/table/test_init.py:
##########
@@ -1226,6 +1226,20 @@ 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 base_metadata == new_metadata_no_removal

Review Comment:
   With the change above, the update is still recorded:
   
   ```suggestion
       assert new_metadata_no_removal.properties == base_metadata.properties
       assert new_metadata_no_removal.last_updated_ms > 
base_metadata.last_updated_ms
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to