HonahX commented on code in PR #245: URL: https://github.com/apache/iceberg-python/pull/245#discussion_r1477690350
########## pyiceberg/table/__init__.py: ########## @@ -533,6 +551,39 @@ def _(update: SetCurrentSchemaUpdate, base_metadata: TableMetadata, context: _Ta return base_metadata.model_copy(update={"current_schema_id": new_schema_id}) +@_apply_table_update.register(AddPartitionSpecUpdate) +def _(update: AddPartitionSpecUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata: + for spec in base_metadata.partition_specs: + if spec.spec_id == update.spec_id: + raise ValueError(f"Partition spec with id {spec.spec_id} already exists: {spec}") + + context.add_update(update) + return base_metadata.model_copy( + update={ + "partition_specs": base_metadata.partition_specs + [update.spec], + } + ) + + +@_apply_table_update.register(SetDefaultSpecUpdate) +def _(update: SetDefaultSpecUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata: + new_spec_id = update.spec_id + if new_spec_id == base_metadata.default_spec_id: Review Comment: Thanks for the update! I think we also need to handle `spec_id=-1` like: https://github.com/apache/iceberg-python/blob/7fbcc220263228618da8d6871a50a0b82e22a843/pyiceberg/table/__init__.py#L537-L541 to make other catalogs such as `hive` to update metadata correctly. WDYT? Java ref: https://github.com/apache/iceberg/blob/9921937d8285dec9a19fd16b0cd82d451a8aca9e/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1079-L1084 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org