|
37 | 37 | new_table_metadata, |
38 | 38 | ) |
39 | 39 | from pyiceberg.table.refs import SnapshotRef, SnapshotRefType |
40 | | -from pyiceberg.table.snapshots import Operation, Snapshot, Summary |
41 | 40 | from pyiceberg.table.sorting import NullOrder, SortDirection, SortField, SortOrder |
42 | 41 | from pyiceberg.transforms import IdentityTransform |
43 | 42 | from pyiceberg.typedef import UTF8 |
@@ -146,79 +145,6 @@ def test_parsing_correct_types(example_table_metadata_v2: dict[str, Any]) -> Non |
146 | 145 | assert isinstance(table_metadata.schemas[0].fields[0].field_type, LongType) |
147 | 146 |
|
148 | 147 |
|
149 | | -def test_snapshot_by_id(example_table_metadata_v2: dict[str, Any]) -> None: |
150 | | - table_metadata = TableMetadataV2(**example_table_metadata_v2) |
151 | | - |
152 | | - # Returns the same instance that is in the snapshots list, not a copy |
153 | | - assert table_metadata.snapshot_by_id(3051729675574597004) is table_metadata.snapshots[0] |
154 | | - assert table_metadata.snapshot_by_id(3055729675574597004) is table_metadata.snapshots[1] |
155 | | - assert table_metadata.snapshot_by_id(-1) is None |
156 | | - |
157 | | - |
158 | | -def test_snapshot_by_id_index_is_invalidated_on_model_copy(example_table_metadata_v2: dict[str, Any]) -> None: |
159 | | - """The snapshot lookup index must not survive a model_copy that replaces the snapshots.""" |
160 | | - table_metadata = TableMetadataV2(**example_table_metadata_v2) |
161 | | - |
162 | | - # Build the index before copying, so a stale one would be carried over |
163 | | - assert table_metadata.snapshot_by_id(3051729675574597004) is not None |
164 | | - |
165 | | - new_snapshot = Snapshot( |
166 | | - snapshot_id=1, |
167 | | - parent_snapshot_id=3055729675574597004, |
168 | | - sequence_number=35, |
169 | | - timestamp_ms=1602638573591, |
170 | | - manifest_list="s3://bucket/test/manifest-list", |
171 | | - summary=Summary(Operation.APPEND), |
172 | | - schema_id=1, |
173 | | - ) |
174 | | - with_added = table_metadata.model_copy(update={"snapshots": table_metadata.snapshots + [new_snapshot]}) |
175 | | - assert with_added.snapshot_by_id(1) is new_snapshot |
176 | | - assert with_added.snapshot_by_id(3051729675574597004) is not None |
177 | | - |
178 | | - without_first = with_added.model_copy(update={"snapshots": with_added.snapshots[1:]}) |
179 | | - assert without_first.snapshot_by_id(3051729675574597004) is None |
180 | | - assert without_first.snapshot_by_id(1) is new_snapshot |
181 | | - |
182 | | - # The original is unaffected by either copy |
183 | | - assert table_metadata.snapshot_by_id(1) is None |
184 | | - assert table_metadata.snapshot_by_id(3051729675574597004) is not None |
185 | | - |
186 | | - |
187 | | -def test_snapshot_by_id_reflects_in_place_snapshot_list_mutation(example_table_metadata_v2: dict[str, Any]) -> None: |
188 | | - """The snapshot lookup must not go stale when the snapshots list itself is mutated in place.""" |
189 | | - table_metadata = TableMetadataV2(**example_table_metadata_v2) |
190 | | - snapshot_id = 3051729675574597004 |
191 | | - |
192 | | - # Build the index before mutating, so a stale one would still be in place |
193 | | - assert table_metadata.snapshot_by_id(snapshot_id) is not None |
194 | | - |
195 | | - # Replacing an entry: the lookup must return the new instance, not the replaced one |
196 | | - altered = table_metadata.snapshots[0].model_copy(update={"summary": Summary(Operation.DELETE)}) |
197 | | - table_metadata.snapshots[0] = altered |
198 | | - assert table_metadata.snapshot_by_id(snapshot_id) is altered |
199 | | - |
200 | | - # Reordering: ids still resolve to the right snapshots |
201 | | - table_metadata.snapshots.reverse() |
202 | | - assert table_metadata.snapshot_by_id(snapshot_id) is altered |
203 | | - assert table_metadata.snapshot_by_id(3055729675574597004) is table_metadata.snapshots[0] |
204 | | - |
205 | | - # Removing: the id is gone |
206 | | - table_metadata.snapshots.clear() |
207 | | - assert table_metadata.snapshot_by_id(snapshot_id) is None |
208 | | - |
209 | | - |
210 | | -def test_snapshot_by_id_index_is_not_serialized(example_table_metadata_v2: dict[str, Any]) -> None: |
211 | | - """The memoized index is an implementation detail and must stay out of the serialized form.""" |
212 | | - table_metadata = TableMetadataV2(**example_table_metadata_v2) |
213 | | - assert table_metadata.snapshot_by_id(3051729675574597004) is not None |
214 | | - |
215 | | - assert "_id_to_snapshot_position" not in table_metadata.model_dump() |
216 | | - assert "_id_to_snapshot_position" not in table_metadata.model_dump_json() |
217 | | - assert "_id_to_snapshot_position" not in TableMetadataV2.model_fields |
218 | | - # Two equal instances stay equal when only one of them has built the index |
219 | | - assert table_metadata == TableMetadataV2(**example_table_metadata_v2) |
220 | | - |
221 | | - |
222 | 148 | def test_updating_metadata(example_table_metadata_v2: dict[str, Any]) -> None: |
223 | 149 | """Test creating a new TableMetadata instance that's an updated version of |
224 | 150 | an existing TableMetadata instance""" |
|
0 commit comments