grihabor commented on code in PR #1598:
URL: https://github.com/apache/iceberg-python/pull/1598#discussion_r1948730520
##########
pyiceberg/table/update/snapshot.py:
##########
@@ -749,6 +750,28 @@ def _commit(self) -> UpdatesAndRequirements:
"""Apply the pending changes and commit."""
return self._updates, self._requirements
+ def _remove_ref_snapshot(self, ref_name: str) -> ManageSnapshots:
+ """Remove a snapshot ref.
+
+ Args:
+ ref_name: branch / tag name to remove
+ Stages the updates and requirements for the remove-snapshot-ref.
+ Returns
+ This method for chaining
+ """
+ updates = (RemoveSnapshotRefUpdate(ref_name=ref_name),)
Review Comment:
I didn't get it
##########
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:
Review Comment:
I don't mind, I believe it was copied from
https://github.com/apache/iceberg-python/pull/822
##########
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:
Are you sure we want to modify existing metadata? All the other code in the
repo I've seen creates a copy:
```
metadata_updates["refs"] = {**base_metadata.refs, update.ref_name:
snapshot_ref}
```
--
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]