Skip to content

Commit dae3aab

Browse files
committed
move apis from Transaction to Table
1 parent 91a86fa commit dae3aab

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pyiceberg/table/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,6 @@ def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs: Any) ->
340340
updates = properties or kwargs
341341
return self._apply((SetPropertiesUpdate(updates=updates),))
342342

343-
def rollback_to_snapshot(self, snapshot_id: int) -> Transaction:
344-
if self.table_metadata.snapshot_by_id(snapshot_id) is None:
345-
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
346-
if snapshot_id not in [ancestor.ancestor_id for ancestor in self.current_ancestors()]:
347-
raise ValidationError(f"Cannot roll back to snapshot, not an ancestor of the current state: {snapshot_id}")
348-
return self.set_ref_snapshot(snapshot_id=snapshot_id, ref_name="main", type="branch")
349-
350-
def rollback_to_timestamp(self, timestamp: int) -> Transaction:
351-
if (snapshot := self.latest_snapshot_before_timestamp(timestamp)) is None:
352-
raise ValidationError(f"Cannot roll back, no valid snapshot older than: {timestamp}")
353-
return self.set_ref_snapshot(snapshot_id=snapshot.snapshot_id, ref_name="main", type="branch")
354-
355-
def set_current_snapshot(self, snapshot_id: int) -> None:
356-
if self.table_metadata.snapshot_by_id(snapshot_id) is None:
357-
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
358-
return self.set_ref_snapshot(snapshot_id=snapshot_id, ref_name="main", type="branch")
359-
360343
def update_schema(self, allow_incompatible_changes: bool = False, case_sensitive: bool = True) -> UpdateSchema:
361344
"""Create a new UpdateSchema to alter the columns of this table.
362345
@@ -1307,6 +1290,23 @@ def snapshot_by_name(self, name: str) -> Optional[Snapshot]:
13071290
return self.snapshot_by_id(ref.snapshot_id)
13081291
return None
13091292

1293+
def rollback_to_snapshot(self, snapshot_id: int) -> Transaction:
1294+
if self.snapshot_by_id(snapshot_id) is None:
1295+
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
1296+
if snapshot_id not in [ancestor.ancestor_id for ancestor in self.current_ancestors()]:
1297+
raise ValidationError(f"Cannot roll back to snapshot, not an ancestor of the current state: {snapshot_id}")
1298+
return self.set_ref_snapshot(snapshot_id=snapshot_id, parent_snapshot_id=self.current_snapshot().snapshot_id, ref_name="main", type="branch")
1299+
1300+
def rollback_to_timestamp(self, timestamp: int) -> Transaction:
1301+
if (snapshot := self.latest_snapshot_before_timestamp(timestamp)) is None:
1302+
raise ValidationError(f"Cannot roll back, no valid snapshot older than: {timestamp}")
1303+
return self.set_ref_snapshot(snapshot_id=snapshot.snapshot_id, parent_snapshot_id=self.current_snapshot().snapshot_id, ref_name="main", type="branch")
1304+
1305+
def set_current_snapshot(self, snapshot_id: int) -> Transaction:
1306+
if self.snapshot_by_id(snapshot_id) is None:
1307+
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
1308+
return self.set_ref_snapshot(snapshot_id=snapshot_id, parent_snapshot_id=self.current_snapshot().snapshot_id, ref_name="main", type="branch")
1309+
13101310
def history(self) -> List[SnapshotLogEntry]:
13111311
"""Get the snapshot history of this table."""
13121312
return self.metadata.snapshot_log

0 commit comments

Comments
 (0)