sohailshk opened a new pull request, #4307: URL: https://github.com/apache/iceberg-python/pull/4307
Closes #4306 # Rationale for this change `update_spec().remove_field(name).add_field(..., name)` raised `Cannot add duplicate partition field name` because `add_field` checked whether the new field's id was being removed instead of the existing field's id. Replacing a partition field while keeping its name, for example to change the number of buckets, works in Java (`BaseUpdatePartitionSpec.addField`). This checks the existing field instead. On v1 tables the removed field stays in the spec as a void transform, so it is renamed to `<name>_<fieldId>`, as Java does. ## Are these changes tested? Yes: `test_update_spec_remove_and_add_field_with_same_name` in `tests/table/test_init.py` replaces a bucket field with a new one of the same name on v1 and v2 tables and checks the resulting spec (on v1 the removed field becomes `y_shard_1001` with a void transform). It fails on `main` and passes with this change. `tests/table` and `tests/test_schema.py`: 889 passed. `ruff check` and `ruff format --check` (0.14.3) pass on the changed files. ## Are there any user-facing changes? Removing a partition field and adding a new one with the same name in one `update_spec()` now works instead of raising. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
