Skip to content

Fix moving a column that was deleted and added back in the same update - #4365

Open
chenjian2664 wants to merge 1 commit into
apache:mainfrom
chenjian2664:chenjian2664/bytequay/fix-move-of-deleted-and-re-added-column
Open

chenjian2664 wants to merge 1 commit into
apache:mainfrom
chenjian2664:chenjian2664/bytequay/fix-move-of-deleted-and-re-added-column

Conversation

@chenjian2664

Copy link
Copy Markdown
Contributor

Rationale for this change

Within one update_schema(), deleting a column, adding it back under the same name and then moving it with move_first, move_before or move_after raises a bare StopIteration. This is a natural way to replace a column with an incompatible type while keeping its position. The move resolved the name against the existing schema first and picked up the deleted field.

The lookup now checks columns added in the same update first, as Java's SchemaUpdate.findForMove does.

Are these changes tested?

Are there any user-facing changes?

@chenjian2664
chenjian2664 marked this pull request as ready for review November 14, 2026 11:22
Copilot AI balanced review requested due to automatic review settings November 14, 2026 11:22

Copilot AI 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.

🟡 Changes recommended

The added-column lookup ignores case_sensitive=False, so moving differently cased replacement columns or using them as anchors can resolve deleted field IDs and raise StopIteration.

1 open issue
What changed in this PR

This PR fixes schema updates that delete a column, add it back under the same name, and then move it by prioritizing newly added columns during move lookup.

Changes:

  • Resolve move targets against columns added in the current update before the existing schema.
  • Add a regression test for replacing a column’s type and moving it after another column.
File Description
tests/​table/​test_init.py Tests column replacement and reordering within one schema update.
pyiceberg/​table/​update/​schema.py Prioritizes newly added columns when resolving move targets.

Review effort: Balanced

Comment thread pyiceberg/table/update/schema.py Outdated
Comment on lines +507 to +508
if (added_id := self._added_name_to_id.get(name)) is not None:
return added_id
Deleting a column, adding it back under the same name and then moving it
in one update_schema() raised a bare StopIteration: the move resolved the
name to the deleted field. Check the columns added in the update first,
and track their names in case-aware form so case_sensitive=False also
finds them, as Java's SchemaUpdate.findForMove does.
@chenjian2664
chenjian2664 force-pushed the chenjian2664/bytequay/fix-move-of-deleted-and-re-added-column branch from a42f2a9 to d9be5f2 Compare November 14, 2026 13:18

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.

2 participants