Repository navigation
Undelete a partition field re-added in the same update - #4476
Draft
rahulsmahadev wants to merge 3 commits into
Draft
rahulsmahadev wants to merge 3 commits into
rahulsmahadev wants to merge 3 commits into
Conversation
Removing a partition field and adding it back with the same name, source and transform in one update created a new field (a void field and a new id on v1, a reordered spec on v2). add_field now keeps the removed field, with its id and position, as Java's rewriteDeleteAndAddField does. Re-adds under another name are unchanged. Co-authored-by: Isaac <[email protected]>
Contributor
Author
|
@kevinjqliu, you merged #4110 (reuse partition field IDs on v3 tables), which this builds on. Could you take a look when you have a chance? Thanks! |
Co-authored-by: Isaac <[email protected]>
The re-add under another name and the swap of two removed names asserted main's results, which differ from Java (Java restores and renames the removed field). Remove that test and a redundant conflict case, test renaming a restored field, name the time transform test for both orders, and describe the restore condition in the docstring. Co-authored-by: Isaac <[email protected]>
rahulsmahadev
marked this pull request as draft
December 1, 2026 02:16
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Bug: removing a partition field and adding it back with the same source, transform and name in one update should leave the spec unchanged. PyIceberg adds a new field instead:
On format-version 2, when the field is not the last one, the re-added field moves to the end and a new spec is written.
Fix:
add_fieldrestores the removed field, with its id, position and name, when it is added back with the same source and transform and either no name or its own name. This matches Java'srewriteDeleteAndAddField. Restoring a removed time transform alongside another time transform added in the same update works in either order, as in Java; main raisesCannot add time partition field.Java callers: Spark's REPLACE PARTITION FIELD converts SQL transforms to Iceberg terms and removes/adds in one update; Flink's TableUpdater does this for PartitionSpecEvolution's diff of the current and requested specs. This PR covers Python's update_spec().
Re-adds under another name and unnamed re-adds after a new field takes the removed name retain main's behaviour. Java restores and renames the removed field in these cases; that remains a follow-up.
Builds on #4110 (partition field ID reuse on v3 tables) and #4307 (a new field can take a removed field's name).
Are these changes tested?
Yes.
test_update_spec_remove_and_add_same_field_in_one_update(v1 and v2, first and last field),test_update_spec_remove_field_added_back_in_same_update(removing the field again),test_update_spec_rename_field_added_back_in_same_update(renaming it) andtest_update_spec_restore_time_transform_with_added_time_transform(both add orders, v1 and v2) fail on main and pass with this change.test_update_spec_add_field_conflicts_with_added_field(a name or a transform already added in the update) passes on main and with this change; Java rejects these too.test_update_spec_remove_and_add_renamed_field_in_one_update(a field renamed in an earlier update, restored under its new name, then a later add of that name) fails on main and passes with this change.test_update_spec_remove_and_add_same_field_reuses_idgains a v1 case, which fails on main.Are there any user-facing changes?
Yes. Removing and re-adding the same source, transform and name in one update preserves the spec (no void field on v1, no new spec id). Restoring a removed time transform alongside another time transform added in the same update now works in either order (Java accepts; main raises). A restored field can be removed or renamed again in the same update, as in Java; main raised. Re-adds under a different name are unchanged from main. An unnamed re-add keeps the current partition name, as Java does. Main generated a default name on v1 or could reuse a historical name on v2/v3. A later add can no longer take the restored name.
This pull request and its description were written by Isaac.