Fokko commented on code in PR #1598: URL: https://github.com/apache/iceberg-python/pull/1598#discussion_r1939200058
########## pyiceberg/table/update/__init__.py: ########## @@ -466,6 +466,21 @@ def _(update: SetSnapshotRefUpdate, base_metadata: TableMetadata, context: _Tabl return base_metadata.model_copy(update=metadata_updates) +@_apply_table_update.register(RemoveSnapshotRefUpdate) +def _(update: RemoveSnapshotRefUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata: + if (existing_ref := base_metadata.refs.get(update.ref_name, None)) is None: + return base_metadata + + if base_metadata.snapshot_by_id(existing_ref.snapshot_id) is None: + raise ValueError(f"Cannot remove {update.ref_name} ref with unknown snapshot {existing_ref.snapshot_id}") + + current_snapshot_id = None if update.ref_name == MAIN_BRANCH else base_metadata.current_snapshot_id + + metadata_refs = {ref_name: ref for ref_name, ref in base_metadata.refs.items() if ref_name != update.ref_name} Review Comment: Here we iterate over the complete dict, which is pretty expensive. Since we know that the key exists, we can also do: ```suggestion metadata_refs = base_metadata.refs del metadata_refs[update.ref_name] ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org