Repository navigation
Fix moving a nested column added in the same schema update - #4606
Merged
Merged
Conversation
add_column recorded the new column's parent as the path passed in, so a field added to a list or map of structs, or under a struct spelled in another case, could not be moved in the same update. Record the parent by the resolved struct's name in the schema, as for existing fields. Co-authored-by: Isaac <no-reply@databricks.com>
add_column registered the new column for moves only under the path
passed in, so ("points", "z") could not be moved as points.element.z,
and after deleting a column of that name the move hit a StopIteration.
Register both names; the first test now uses table_v2 like its neighbours.
Co-authored-by: Isaac <no-reply@databricks.com>
find_column_name returns "" for a top-level struct named "", which the
schema-name registration treated as the table root, so adding ("", "z")
also registered "z" and moving the top-level z raised StopIteration.
Check for None instead.
Co-authored-by: Isaac <no-reply@databricks.com>
Fokko
approved these changes
Dec 3, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Verified the fix against Java's SchemaUpdate.internalAddColumn, which also resolves the parent via schema.findColumnName. Nice edge cases covered, like the struct named "". Thanks @rahulsmahadev 🚀
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: moving a nested column added in the same
update_schema()fails whenadd_columngot a list or map of structs as the parent, and moving it before or after another field fails when it got a struct spelled in another case withcase_sensitive=False:A column added as
("points", "z")also cannot be moved by its name in the schema,("points", "element", "z"). That raisesCannot move missing column, or a bareStopIterationif a column of that name was deleted in the same update, as in #4365. The moves look up and compare the parent of each field by its name in the schema (points.element,person), butadd_columnrecorded the path as passed in (points,Person), and registered the column only under that path.Fix:
add_columnrecords the parent of the new column by the schema's name for the struct it resolved, like the existing fields, and also registers the column under its name in the schema (points.element.z). Moving it to another struct still raises.Java does the same:
SchemaUpdate.internalAddColumnresolves a list or map to its element or value, records the parent, whichinternalMovecompares, and registers the column under its name in the schema. Java accepts only that name, so it rejects("points", "z")above withCannot move missing column; PyIceberg accepts both, so moves by the path passed in that work on main keep working. Spark'sADD COLUMN ... FIRST | AFTERtakes this path (Spark3Util.applySchemaChangescallsaddColumnand thenmoveFirstormoveAfteron the sameUpdateSchema); this PR fixes the matching step inUpdateSchema.add_column.Follow-up to #4365, which fixed the name lookup for columns added in the same update.
Are these changes tested?
Yes,
test_move_nested_column_added_in_same_updateandtest_move_relative_to_nested_column_added_in_same_updateintests/table/test_init.pycover list, map and case-insensitive parents, both names, a column deleted and added back, anchors and a move to another struct. Both fail on main with the errors above and pass with this change.Are there any user-facing changes?
Yes, these updates work now instead of raising. Please add the
changeloglabel.This pull request and its description were written by Isaac.