@@ -340,6 +340,23 @@ def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs: Any) ->
340
340
updates = properties or kwargs
341
341
return self ._apply ((SetPropertiesUpdate (updates = updates ),))
342
342
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
+
343
360
def update_schema (self , allow_incompatible_changes : bool = False , case_sensitive : bool = True ) -> UpdateSchema :
344
361
"""Create a new UpdateSchema to alter the columns of this table.
345
362
@@ -1881,7 +1898,8 @@ def union_by_name(self, new_schema: Union[Schema, "pa.Schema"]) -> UpdateSchema:
1881
1898
visit_with_partner (
1882
1899
Catalog ._convert_schema_if_needed (new_schema ),
1883
1900
- 1 ,
1884
- UnionByNameVisitor (update_schema = self , existing_schema = self ._schema , case_sensitive = self ._case_sensitive ), # type: ignore
1901
+ UnionByNameVisitor (update_schema = self , existing_schema = self ._schema , case_sensitive = self ._case_sensitive ),
1902
+ # type: ignore
1885
1903
PartnerIdByNameAccessor (partner_schema = self ._schema , case_sensitive = self ._case_sensitive ),
1886
1904
)
1887
1905
return self
0 commit comments