Skip to content

Commit ca63831

Browse files
committed
use tbl.history() instead of ancestors_of()
We don't need to find all the ancestors, we only need to validate that the snapshot is an ancestor, i.e if it was ever current.
1 parent 45c25db commit ca63831

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

pyiceberg/table/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
SnapshotLogEntry,
114114
SnapshotSummaryCollector,
115115
Summary,
116-
ancestors_of,
117116
update_snapshot_summaries,
118117
)
119118
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
@@ -2038,10 +2037,7 @@ def rollback_to_snapshot(self, snapshot_id: int) -> ManageSnapshots:
20382037
self._commit_if_ref_updates_exist()
20392038
if self._transaction._table.snapshot_by_id(snapshot_id) is None:
20402039
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
2041-
if snapshot_id not in {
2042-
ancestor.snapshot_id
2043-
for ancestor in ancestors_of(self._transaction._table.current_snapshot(), self._transaction.table_metadata)
2044-
}:
2040+
if snapshot_id not in {ancestor.snapshot_id for ancestor in self._transaction._table.history()}:
20452041
raise ValidationError(f"Cannot roll back to snapshot, not an ancestor of the current state: {snapshot_id}")
20462042

20472043
update, requirement = self._transaction._set_ref_snapshot(snapshot_id=snapshot_id, ref_name="main", type="branch")

0 commit comments

Comments
 (0)