|
66 | 66 | ) |
67 | 67 | from pyiceberg.table.statistics import BlobMetadata, PartitionStatisticsFile, 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 | RemovePartitionStatisticsUpdate, |
80 | 82 | RemovePropertiesUpdate, |
81 | 83 | RemoveSnapshotRefUpdate, |
@@ -1286,6 +1288,38 @@ def test_update_metadata_log_overflow(table_v2: Table) -> None: |
1286 | 1288 | assert len(new_metadata.metadata_log) == 1 |
1287 | 1289 |
|
1288 | 1290 |
|
| 1291 | +def test_remove_partition_spec_update(table_v2: Table) -> None: |
| 1292 | + base_metadata = table_v2.metadata |
| 1293 | + new_spec = PartitionSpec(PartitionField(source_id=2, field_id=1001, transform=IdentityTransform(), name="y"), spec_id=1) |
| 1294 | + metadata_with_new_spec = update_table_metadata(base_metadata, (AddPartitionSpecUpdate(spec=new_spec),)) |
| 1295 | + |
| 1296 | + assert len(metadata_with_new_spec.partition_specs) == 2 |
| 1297 | + |
| 1298 | + update = RemovePartitionSpecsUpdate(spec_ids=[1]) |
| 1299 | + updated_metadata = update_table_metadata( |
| 1300 | + metadata_with_new_spec, |
| 1301 | + (update,), |
| 1302 | + ) |
| 1303 | + |
| 1304 | + assert len(updated_metadata.partition_specs) == 1 |
| 1305 | + |
| 1306 | + |
| 1307 | +def test_remove_partition_spec_update_spec_does_not_exist(table_v2: Table) -> None: |
| 1308 | + update = RemovePartitionSpecsUpdate( |
| 1309 | + spec_ids=[123], |
| 1310 | + ) |
| 1311 | + with pytest.raises(ValueError, match="Partition spec with id 123 does not exist"): |
| 1312 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1313 | + |
| 1314 | + |
| 1315 | +def test_remove_partition_spec_update_default_spec(table_v2: Table) -> None: |
| 1316 | + update = RemovePartitionSpecsUpdate( |
| 1317 | + spec_ids=[0], |
| 1318 | + ) |
| 1319 | + with pytest.raises(ValueError, match="Cannot remove default partition spec: 0"): |
| 1320 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1321 | + |
| 1322 | + |
1289 | 1323 | def test_set_statistics_update(table_v2_with_statistics: Table) -> None: |
1290 | 1324 | snapshot_id = table_v2_with_statistics.metadata.current_snapshot_id |
1291 | 1325 |
|
|
0 commit comments