Skip to content

Commit cb9f0c9

Browse files
committed
Draft ready
1 parent e80c41c commit cb9f0c9

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

pyiceberg/table/update/snapshot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,13 @@ def _commit(self) -> Tuple[Tuple[TableUpdate, ...], Tuple[TableRequirement, ...]
885885
if not self._ids_to_remove:
886886
raise ValueError("No snapshot IDs marked for expiration.")
887887

888-
888+
# print all children snapshots of the current snapshot
889+
print(f"Current snapshot ID of {self._transaction._table.current_snapshot()} which has {len(self._transaction._table.snapshots())}")
889890
print(f"Totals number of snapshot IDs to expire: {len(self._ids_to_remove)}")
890891
print(f"Total number of snapshots in the table: {len(self._transaction.table_metadata.snapshots)}")
891892
# Ensure current snapshots in refs are not marked for removal
892893
current_snapshot_ids = {ref.snapshot_id for ref in self._transaction.table_metadata.refs.values()}
894+
893895
print(f"Current snapshot IDs in refs: {current_snapshot_ids}")
894896
print(f"Snapshot IDs marked for removal: {self._ids_to_remove}")
895897
conflicting_ids = self._ids_to_remove.intersection(current_snapshot_ids)
@@ -910,7 +912,7 @@ def _commit(self) -> Tuple[Tuple[TableUpdate, ...], Tuple[TableRequirement, ...]
910912
for ref_name, ref in self._transaction.table_metadata.refs.items()
911913
if ref.snapshot_id not in self._ids_to_remove
912914
)
913-
915+
914916
self._requirements += requirements
915917
return self._updates, self._requirements
916918

tests/table/test_expire_snapshots.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,11 @@ def test_remove_snapshot(table_v2_with_extensive_snapshots: Table):
164164
assert table.metadata is not None, "Table metadata is None"
165165
assert table.metadata.current_snapshot_id is not None, "Current snapshot ID is None"
166166

167-
initial_snapshot_id = table.metadata.current_snapshot_id
167+
snapshot_to_expire = 3051729675574599003
168168

169169
# Ensure the table has snapshots
170170
assert table.metadata.snapshots is not None, "Snapshots list is None"
171171
assert len(table.metadata.snapshots) == 2000, f"Expected 2000 snapshots, got {len(table.metadata.snapshots)}"
172-
173-
# Find an older snapshot that is not the current snapshot
174-
for snapshot in table.metadata.snapshots:
175-
if snapshot.snapshot_id != initial_snapshot_id and snapshot.snapshot_id not in table.metadata.refs.values():
176-
snapshot_to_expire = snapshot.snapshot_id
177-
break
178172

179173
assert snapshot_to_expire is not None, "No valid snapshot found to expire"
180174

@@ -187,5 +181,4 @@ def test_remove_snapshot(table_v2_with_extensive_snapshots: Table):
187181

188182
# Use the built-in pytest capsys fixture to capture printed output
189183
print(f"Snapshot ID {snapshot_to_expire} expired successfully")
190-
print(f"Number of snapshots after expiry: {len(table.metadata.snapshots)}")
191-
print(table.metadata.snapshots)
184+
print(f"Number of snapshots after expiry: {table.metadata}")

0 commit comments

Comments
 (0)