Skip to content

Commit cfb4061

Browse files
committed
refactor: simplify snapshot expiration logic and clean up unused imports
1 parent 0e72ccc commit cfb4061

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

pyiceberg/table/maintenance.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def expire_snapshots_older_than(self, timestamp_ms: int) -> None:
104104
snapshots_to_expire.append(snapshot.snapshot_id)
105105

106106
if snapshots_to_expire:
107-
with self.tbl.transaction():
108-
self.expire_snapshots_by_ids(snapshots_to_expire)
107+
self.expire_snapshots_by_ids(snapshots_to_expire)
109108

110109
def expire_snapshots_older_than_with_retention(
111110
self, timestamp_ms: int, retain_last_n: Optional[int] = None, min_snapshots_to_keep: Optional[int] = None
@@ -122,8 +121,7 @@ def expire_snapshots_older_than_with_retention(
122121
)
123122

124123
if snapshots_to_expire:
125-
with self.tbl.transaction():
126-
self.expire_snapshots_by_ids(snapshots_to_expire)
124+
self.expire_snapshots_by_ids(snapshots_to_expire)
127125

128126
def retain_last_n_snapshots(self, n: int) -> None:
129127
"""Keep only the last N snapshots, expiring all others.
@@ -158,8 +156,7 @@ def retain_last_n_snapshots(self, n: int) -> None:
158156
snapshots_to_expire.append(snapshot.snapshot_id)
159157

160158
if snapshots_to_expire:
161-
with self.tbl.transaction():
162-
self.expire_snapshots_by_ids(snapshots_to_expire)
159+
self.expire_snapshots_by_ids(snapshots_to_expire)
163160

164161
def _get_snapshots_to_expire_with_retention(
165162
self, timestamp_ms: Optional[int] = None, retain_last_n: Optional[int] = None, min_snapshots_to_keep: Optional[int] = None
@@ -215,7 +212,7 @@ def _get_snapshots_to_expire_with_retention(
215212

216213
def expire_snapshots_with_retention_policy(
217214
self, timestamp_ms: Optional[int] = None, retain_last_n: Optional[int] = None, min_snapshots_to_keep: Optional[int] = None
218-
) -> List[int]:
215+
) -> None:
219216
"""Comprehensive snapshot expiration with multiple retention strategies.
220217
221218
This method provides a unified interface for snapshot expiration with various
@@ -265,12 +262,7 @@ def expire_snapshots_with_retention_policy(
265262
)
266263

267264
if snapshots_to_expire:
268-
with self.tbl.transaction() as txn:
269-
from pyiceberg.table.update import RemoveSnapshotsUpdate
270-
271-
txn._apply((RemoveSnapshotsUpdate(snapshot_ids=snapshots_to_expire),))
272-
273-
return snapshots_to_expire
265+
self.expire_snapshots_by_ids(snapshots_to_expire)
274266

275267
def _get_protected_snapshot_ids(self, table_metadata: TableMetadata) -> Set[int]:
276268
"""Get the IDs of protected snapshots.

pyiceberg/table/update/snapshot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
AddSnapshotUpdate,
6969
AssertRefSnapshotId,
7070
RemoveSnapshotRefUpdate,
71-
RemoveSnapshotsUpdate,
7271
SetSnapshotRefUpdate,
7372
TableRequirement,
7473
TableUpdate,
@@ -903,4 +902,4 @@ def remove_branch(self, branch_name: str) -> ManageSnapshots:
903902
Returns:
904903
This for method chaining
905904
"""
906-
return self._remove_ref_snapshot(ref_name=branch_name)
905+
return self._remove_ref_snapshot(ref_name=branch_name)

tests/table/test_dedup_data_file_filepaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ def test_deduplicate_data_files_removes_duplicates_in_current_snapshot(
136136
file_names_after: List[str] = [os.path.basename(df.file_path) for df in all_datafiles_after]
137137
# Only one reference should remain after deduplication
138138
assert file_names_after.count(dupe_data_file_path.name) == 1
139-
assert all(isinstance(df, DataFile) for df in removed)
139+
assert all(isinstance(df, DataFile) for df in removed)

0 commit comments

Comments
 (0)