Skip to content

Allow adding a partition field with the name of a removed one - #4307

Merged
Fokko merged 1 commit into
apache:mainfrom
sohailshk:fix/update-spec-reuse-removed-name
Nov 10, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
sohailshk:fix/update-spec-reuse-removed-name

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

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.

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.

Check the existing field instead, and on v1 tables rename the removed
field, which stays in the spec as a void transform, to name_<field id>
as Java does.

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! 🙌 Checked against Java's BaseUpdatePartitionSpec.addField and the void-transform rename on v1 matches. Verified the test fails on main and passes here. Thanks @sohailshk!

@Fokko
Fokko added this pull request to the merge queue Nov 10, 2026
Merged via the queue into apache:main with commit b05d860 Nov 10, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update_spec: removing a partition field and adding one with the same name raises "Cannot add duplicate partition field name"

2 participants