@@ -49,37 +49,38 @@ def test_manage_snapshots_context_manager(catalog: Catalog) -> None:
49
49
tbl = catalog .load_table (identifier )
50
50
assert len (tbl .history ()) > 3
51
51
current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
52
- rollback_snapshot_id = tbl .history ()[- 4 ].snapshot_id
52
+ expected_snapshot_id = tbl .history ()[- 4 ].snapshot_id
53
53
with tbl .manage_snapshots () as ms :
54
54
ms .create_tag (snapshot_id = current_snapshot_id , tag_name = "testing" )
55
- ms .rollback_to_snapshot (snapshot_id = rollback_snapshot_id )
55
+ ms .set_current_snapshot (snapshot_id = expected_snapshot_id )
56
+ ms .create_tag (snapshot_id = expected_snapshot_id , tag_name = "testing2" )
56
57
assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
57
58
assert tbl .metadata .refs ["testing" ].snapshot_id == current_snapshot_id
58
- assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = rollback_snapshot_id , snapshot_ref_type = "branch" )
59
+ assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
60
+ assert tbl .metadata .refs ["testing2" ].snapshot_id == expected_snapshot_id
59
61
60
62
61
63
@pytest .mark .integration
62
64
@pytest .mark .parametrize ("catalog" , [pytest .lazy_fixture ("session_catalog_hive" ), pytest .lazy_fixture ("session_catalog" )])
63
65
def test_rollback_to_snapshot (catalog : Catalog ) -> None :
64
- identifier = "default.test_table_snapshot_operations "
66
+ identifier = "default.test_table_rollback_to_snapshot_id "
65
67
tbl = catalog .load_table (identifier )
66
68
assert len (tbl .history ()) > 3
67
- rollback_snapshot_id = tbl .history ()[ - 3 ]. snapshot_id
69
+ rollback_snapshot_id = tbl .current_snapshot (). parent_snapshot_id # type: ignore
68
70
current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
69
- tbl .manage_snapshots ().rollback_to_snapshot (snapshot_id = rollback_snapshot_id ).commit ()
71
+ tbl .manage_snapshots ().rollback_to_snapshot (snapshot_id = rollback_snapshot_id ).commit () # type: ignore
70
72
assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
71
73
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = rollback_snapshot_id , snapshot_ref_type = "branch" )
72
74
73
75
74
76
@pytest .mark .integration
75
77
@pytest .mark .parametrize ("catalog" , [pytest .lazy_fixture ("session_catalog_hive" ), pytest .lazy_fixture ("session_catalog" )])
76
78
def test_rollback_to_timestamp (catalog : Catalog ) -> None :
77
- identifier = "default.test_table_snapshot_operations "
79
+ identifier = "default.test_table_rollback_to_snapshot_id "
78
80
tbl = catalog .load_table (identifier )
79
- assert len (tbl .history ()) > 3
80
- current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
81
- timestamp = tbl .history ()[- 2 ].timestamp_ms
82
- expected_snapshot_id = tbl .history ()[- 3 ].snapshot_id
81
+ assert len (tbl .history ()) > 4
82
+ current_snapshot_id , timestamp = tbl .history ()[- 1 ].snapshot_id , tbl .history ()[- 1 ].timestamp_ms
83
+ expected_snapshot_id = tbl .snapshot_by_id (current_snapshot_id ).parent_snapshot_id # type: ignore
83
84
# not inclusive of rollback_timestamp
84
85
tbl .manage_snapshots ().rollback_to_timestamp (timestamp = timestamp ).commit ()
85
86
assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
@@ -107,7 +108,7 @@ def test_set_current_snapshot_with_ref_name(catalog: Catalog) -> None:
107
108
assert len (tbl .history ()) > 3
108
109
current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
109
110
expected_snapshot_id = tbl .history ()[- 3 ].snapshot_id
110
- tbl .manage_snapshots ().create_tag (snapshot_id = expected_snapshot_id , tag_name = "test-tag19 " ).commit ()
111
- tbl .manage_snapshots ().set_current_snapshot (ref_name = "test-tag19 " ).commit ()
111
+ tbl .manage_snapshots ().create_tag (snapshot_id = expected_snapshot_id , tag_name = "test-tag " ).commit ()
112
+ tbl .manage_snapshots ().set_current_snapshot (ref_name = "test-tag " ).commit ()
112
113
assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
113
114
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
0 commit comments