Fix upsert after schema evolution - #3816
Open
kevinjqliu wants to merge 4 commits into
Open
Conversation
kevinjqliu
marked this pull request as ready for review
August 20, 2026 23:33
3 tasks
kevinjqliu
commented
Aug 21, 2026
Comment on lines
+317
to
+322
| def _scan( | ||
| self, | ||
| row_filter: str | BooleanExpression = ALWAYS_TRUE, | ||
| case_sensitive: bool = True, | ||
| branch: str | None = None, | ||
| ) -> DataScan: |
Contributor
Author
There was a problem hiding this comment.
reviewer note:
the change here is only adding
branch: str | None = None,
| file_scan = self._scan(row_filter=delete_filter, case_sensitive=case_sensitive) | ||
| if branch is not None: | ||
| file_scan = file_scan.use_ref(branch) | ||
| file_scan = self._scan(row_filter=delete_filter, case_sensitive=case_sensitive, branch=branch) |
Contributor
Author
There was a problem hiding this comment.
simplifying the logic now that we can pass branch into _scan
Comment on lines
-938
to
-939
| if branch in self.table_metadata.refs: | ||
| matched_iceberg_record_batches_scan = matched_iceberg_record_batches_scan.use_ref(branch) |
Contributor
Author
There was a problem hiding this comment.
this is now part of the _scan logic, by passing branch in directly
| # A schema update does not create a snapshot, so the branch snapshot may use an older schema. | ||
| matched_iceberg_record_batches = _to_arrow_batch_reader_via_file_scan_tasks( | ||
| matched_iceberg_file_scan, | ||
| self.table_metadata.schema(), |
Contributor
Author
There was a problem hiding this comment.
this is the main fix to ensure that we're using the same schema!
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.
Closes #2467
Rationale for this change
Schema updates change the current table schema but do not create snapshots. The target branch can therefore still point to a snapshot with an older
schema_id.Before this change, upsert built its source and target rows with different schemas:
self.table_metadata.schema(), the current transaction schema and the schema recorded on the new snapshot.use_ref()setssnapshot_id, which makesDataScan.projection()use the snapshot schema.After adding
created_at, this produced:When
get_rows_to_updatecasts the source to the target Arrow schema, PyArrow reports:The branch snapshot should determine which files to read, while the current transaction schema should define the rows being compared and written. This change plans files from the target branch and materializes them with the current transaction schema. Older files are projected into the current schema, so the source and matched target rows have the same columns. Snapshot-based projection remains unchanged for normal and time-travel scans.
Are these changes tested?
Yes. Added regression tests for main and a diverged branch.
Are there any user-facing changes?
Yes. Upsert works after schema evolution.