Skip to content

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

Open
sohailshk wants to merge 1 commit into
apache:mainfrom
sohailshk:fix/update-spec-reuse-removed-name
Open

sohailshk wants to merge 1 commit into
apache:mainfrom
sohailshk:fix/update-spec-reuse-removed-name

Conversation

@sohailshk

Copy link
Copy Markdown

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.

This branch has not been deployed

No deployments
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"

1 participant