Repository navigation
Undelete a partition field re-added in the same update - #4476
Open
rahulsmahadev wants to merge 2 commits into
Open
rahulsmahadev wants to merge 2 commits into
rahulsmahadev wants to merge 2 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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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_fieldkeeps the removed field, with its id and position, when it is added back with the same name, source and transform. This matches Java'srewriteDeleteAndAddField. A time transform restored after another time transform was added in the same update is accepted too, 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) andtest_update_spec_restore_time_transform_after_added_time_transform(both add orders, v1 and v2) fail on main and pass with this change.test_update_spec_add_field_with_new_name_after_remove(a re-add under another name, and a swap of two removed names) andtest_update_spec_add_field_conflicts_with_added_field(a name or a transform already added in the update) pass on main and with this change, so they pin main's behaviour.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 after another time transform was added in the same update now works (Java accepts; main raises). 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.