|
66 | 66 | )
|
67 | 67 | from pyiceberg.table.statistics import BlobMetadata, StatisticsFile
|
68 | 68 | from pyiceberg.table.update import (
|
| 69 | + AddPartitionSpecUpdate, |
69 | 70 | AddSnapshotUpdate,
|
70 | 71 | AddSortOrderUpdate,
|
71 | 72 | AssertCreate,
|
|
76 | 77 | AssertLastAssignedPartitionId,
|
77 | 78 | AssertRefSnapshotId,
|
78 | 79 | AssertTableUUID,
|
| 80 | + RemovePartitionSpecsUpdate, |
79 | 81 | RemovePropertiesUpdate,
|
80 | 82 | RemoveSnapshotRefUpdate,
|
81 | 83 | RemoveSnapshotsUpdate,
|
@@ -1267,6 +1269,38 @@ def test_update_metadata_log_overflow(table_v2: Table) -> None:
|
1267 | 1269 | assert len(new_metadata.metadata_log) == 1
|
1268 | 1270 |
|
1269 | 1271 |
|
| 1272 | +def test_remove_partition_spec_update(table_v2: Table) -> None: |
| 1273 | + base_metadata = table_v2.metadata |
| 1274 | + new_spec = PartitionSpec(PartitionField(source_id=2, field_id=1001, transform=IdentityTransform(), name="y"), spec_id=1) |
| 1275 | + metadata_with_new_spec = update_table_metadata(base_metadata, (AddPartitionSpecUpdate(spec=new_spec),)) |
| 1276 | + |
| 1277 | + assert len(metadata_with_new_spec.partition_specs) == 2 |
| 1278 | + |
| 1279 | + update = RemovePartitionSpecsUpdate(spec_ids=[1]) |
| 1280 | + updated_metadata = update_table_metadata( |
| 1281 | + metadata_with_new_spec, |
| 1282 | + (update,), |
| 1283 | + ) |
| 1284 | + |
| 1285 | + assert len(updated_metadata.partition_specs) == 1 |
| 1286 | + |
| 1287 | + |
| 1288 | +def test_remove_partition_spec_update_spec_does_not_exist(table_v2: Table) -> None: |
| 1289 | + update = RemovePartitionSpecsUpdate( |
| 1290 | + spec_ids=[123], |
| 1291 | + ) |
| 1292 | + with pytest.raises(ValueError, match="Partition spec with id 123 does not exist"): |
| 1293 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1294 | + |
| 1295 | + |
| 1296 | +def test_remove_partition_spec_update_default_spec(table_v2: Table) -> None: |
| 1297 | + update = RemovePartitionSpecsUpdate( |
| 1298 | + spec_ids=[0], |
| 1299 | + ) |
| 1300 | + with pytest.raises(ValueError, match="Cannot remove default partition spec: 0"): |
| 1301 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1302 | + |
| 1303 | + |
1270 | 1304 | def test_set_statistics_update(table_v2_with_statistics: Table) -> None:
|
1271 | 1305 | snapshot_id = table_v2_with_statistics.metadata.current_snapshot_id
|
1272 | 1306 |
|
|
0 commit comments