|
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 | RemoveSchemasUpdate, |
@@ -1294,6 +1296,38 @@ def test_update_metadata_log_overflow(table_v2: Table) -> None: |
1294 | 1296 | assert len(new_metadata.metadata_log) == 1 |
1295 | 1297 |
|
1296 | 1298 |
|
| 1299 | +def test_remove_partition_spec_update(table_v2: Table) -> None: |
| 1300 | + base_metadata = table_v2.metadata |
| 1301 | + new_spec = PartitionSpec(PartitionField(source_id=2, field_id=1001, transform=IdentityTransform(), name="y"), spec_id=1) |
| 1302 | + metadata_with_new_spec = update_table_metadata(base_metadata, (AddPartitionSpecUpdate(spec=new_spec),)) |
| 1303 | + |
| 1304 | + assert len(metadata_with_new_spec.partition_specs) == 2 |
| 1305 | + |
| 1306 | + update = RemovePartitionSpecsUpdate(spec_ids=[1]) |
| 1307 | + updated_metadata = update_table_metadata( |
| 1308 | + metadata_with_new_spec, |
| 1309 | + (update,), |
| 1310 | + ) |
| 1311 | + |
| 1312 | + assert len(updated_metadata.partition_specs) == 1 |
| 1313 | + |
| 1314 | + |
| 1315 | +def test_remove_partition_spec_update_spec_does_not_exist(table_v2: Table) -> None: |
| 1316 | + update = RemovePartitionSpecsUpdate( |
| 1317 | + spec_ids=[123], |
| 1318 | + ) |
| 1319 | + with pytest.raises(ValueError, match="Partition spec with id 123 does not exist"): |
| 1320 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1321 | + |
| 1322 | + |
| 1323 | +def test_remove_partition_spec_update_default_spec(table_v2: Table) -> None: |
| 1324 | + update = RemovePartitionSpecsUpdate( |
| 1325 | + spec_ids=[0], |
| 1326 | + ) |
| 1327 | + with pytest.raises(ValueError, match="Cannot remove default partition spec: 0"): |
| 1328 | + update_table_metadata(table_v2.metadata, (update,)) |
| 1329 | + |
| 1330 | + |
1297 | 1331 | def test_remove_schemas_update(table_v2: Table) -> None: |
1298 | 1332 | base_metadata = table_v2.metadata |
1299 | 1333 | assert len(base_metadata.schemas) == 2 |
|
0 commit comments