@@ -903,104 +903,4 @@ def remove_branch(self, branch_name: str) -> ManageSnapshots:
903
903
Returns:
904
904
This for method chaining
905
905
"""
906
- return self ._remove_ref_snapshot (ref_name = branch_name )
907
-
908
-
909
- class ExpireSnapshots (UpdateTableMetadata ["ExpireSnapshots" ]):
910
- """
911
- Expire snapshots by ID.
912
-
913
- Use table.expire_snapshots().<operation>().commit() to run a specific operation.
914
- Use table.expire_snapshots().<operation-one>().<operation-two>().commit() to run multiple operations.
915
- Pending changes are applied on commit.
916
- """
917
-
918
- _snapshot_ids_to_expire : Set [int ] = set ()
919
- _updates : Tuple [TableUpdate , ...] = ()
920
- _requirements : Tuple [TableRequirement , ...] = ()
921
-
922
- def _commit (self ) -> UpdatesAndRequirements :
923
- """
924
- Commit the staged updates and requirements.
925
-
926
- This will remove the snapshots with the given IDs, but will always skip protected snapshots (branch/tag heads).
927
-
928
- Returns:
929
- Tuple of updates and requirements to be committed,
930
- as required by the calling parent apply functions.
931
- """
932
- # Remove any protected snapshot IDs from the set to expire, just in case
933
- protected_ids = self ._get_protected_snapshot_ids ()
934
- self ._snapshot_ids_to_expire -= protected_ids
935
- update = RemoveSnapshotsUpdate (snapshot_ids = self ._snapshot_ids_to_expire )
936
- self ._updates += (update ,)
937
- return self ._updates , self ._requirements
938
-
939
- def _get_protected_snapshot_ids (self ) -> Set [int ]:
940
- """
941
- Get the IDs of protected snapshots.
942
-
943
- These are the HEAD snapshots of all branches and all tagged snapshots. These ids are to be excluded from expiration.
944
-
945
- Returns:
946
- Set of protected snapshot IDs to exclude from expiration.
947
- """
948
- protected_ids : Set [int ] = set ()
949
-
950
- for ref in self ._transaction .table_metadata .refs .values ():
951
- if ref .snapshot_ref_type in [SnapshotRefType .TAG , SnapshotRefType .BRANCH ]:
952
- protected_ids .add (ref .snapshot_id )
953
-
954
- return protected_ids
955
-
956
- def expire_snapshot_by_id (self , snapshot_id : int ) -> ExpireSnapshots :
957
- """
958
- Expire a snapshot by its ID.
959
-
960
- This will mark the snapshot for expiration.
961
-
962
- Args:
963
- snapshot_id (int): The ID of the snapshot to expire.
964
- Returns:
965
- This for method chaining.
966
- """
967
- if self ._transaction .table_metadata .snapshot_by_id (snapshot_id ) is None :
968
- raise ValueError (f"Snapshot with ID { snapshot_id } does not exist." )
969
-
970
- if snapshot_id in self ._get_protected_snapshot_ids ():
971
- raise ValueError (f"Snapshot with ID { snapshot_id } is protected and cannot be expired." )
972
-
973
- self ._snapshot_ids_to_expire .add (snapshot_id )
974
-
975
- return self
976
-
977
- def expire_snapshots_by_ids (self , snapshot_ids : List [int ]) -> "ExpireSnapshots" :
978
- """
979
- Expire multiple snapshots by their IDs.
980
-
981
- This will mark the snapshots for expiration.
982
-
983
- Args:
984
- snapshot_ids (List[int]): List of snapshot IDs to expire.
985
- Returns:
986
- This for method chaining.
987
- """
988
- for snapshot_id in snapshot_ids :
989
- self .expire_snapshot_by_id (snapshot_id )
990
- return self
991
-
992
- def expire_snapshots_older_than (self , timestamp_ms : int ) -> "ExpireSnapshots" :
993
- """
994
- Expire all unprotected snapshots with a timestamp older than a given value.
995
-
996
- Args:
997
- timestamp_ms (int): Only snapshots with timestamp_ms < this value will be expired.
998
-
999
- Returns:
1000
- This for method chaining.
1001
- """
1002
- protected_ids = self ._get_protected_snapshot_ids ()
1003
- for snapshot in self ._transaction .table_metadata .snapshots :
1004
- if snapshot .timestamp_ms < timestamp_ms and snapshot .snapshot_id not in protected_ids :
1005
- self ._snapshot_ids_to_expire .add (snapshot .snapshot_id )
1006
- return self
906
+ return self ._remove_ref_snapshot (ref_name = branch_name )
0 commit comments