Skip to content

Commit e80c41c

Browse files
committed
adding print statements to help with debugging
1 parent 4628ede commit e80c41c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

pyiceberg/table/update/snapshot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,25 +885,32 @@ 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+
889+
print(f"Totals number of snapshot IDs to expire: {len(self._ids_to_remove)}")
890+
print(f"Total number of snapshots in the table: {len(self._transaction.table_metadata.snapshots)}")
888891
# Ensure current snapshots in refs are not marked for removal
889892
current_snapshot_ids = {ref.snapshot_id for ref in self._transaction.table_metadata.refs.values()}
893+
print(f"Current snapshot IDs in refs: {current_snapshot_ids}")
894+
print(f"Snapshot IDs marked for removal: {self._ids_to_remove}")
890895
conflicting_ids = self._ids_to_remove.intersection(current_snapshot_ids)
896+
print(f"Conflicting snapshot IDs: {conflicting_ids}")
897+
891898
if conflicting_ids:
892899
# Remove references to the conflicting snapshots before expiring them
893900
for ref_name, ref in list(self._transaction.table_metadata.refs.items()):
894901
if ref.snapshot_id in conflicting_ids:
895902
self._updates += (RemoveSnapshotRefUpdate(ref_name=ref_name),)
896903

897904
# Remove the snapshots
898-
updates = (RemoveSnapshotsUpdate(snapshot_ids=list(self._ids_to_remove)),)
905+
self._updates = (RemoveSnapshotsUpdate(snapshot_ids=list(self._ids_to_remove)),)
899906

900907
# Ensure refs haven't changed (snapshot ID consistency check)
901908
requirements = tuple(
902909
AssertRefSnapshotId(snapshot_id=ref.snapshot_id, ref=ref_name)
903910
for ref_name, ref in self._transaction.table_metadata.refs.items()
904911
if ref.snapshot_id not in self._ids_to_remove
905912
)
906-
self._updates += updates
913+
907914
self._requirements += requirements
908915
return self._updates, self._requirements
909916

tests/table/test_expire_snapshots.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,8 @@ def test_remove_snapshot(table_v2_with_extensive_snapshots: Table):
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-
# Print snapshot information for debugging
174-
print(f"Initial snapshot ID: {initial_snapshot_id}")
175-
print(f"Number of snapshots before expiry: {len(table.metadata.snapshots)}")
176-
172+
177173
# Find an older snapshot that is not the current snapshot
178-
snapshot_to_expire = None
179174
for snapshot in table.metadata.snapshots:
180175
if snapshot.snapshot_id != initial_snapshot_id and snapshot.snapshot_id not in table.metadata.refs.values():
181176
snapshot_to_expire = snapshot.snapshot_id
@@ -190,5 +185,7 @@ def test_remove_snapshot(table_v2_with_extensive_snapshots: Table):
190185
assert snapshot_to_expire not in [snapshot.snapshot_id for snapshot in table.metadata.snapshots], \
191186
f"Snapshot ID {snapshot_to_expire} was not removed"
192187

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

0 commit comments

Comments
 (0)