Skip to content

Fix time-travel row filters to use the snapshot schema - #4158

Open
rich7420 wants to merge 7 commits into
apache:mainfrom
rich7420:fix/4138-snapshot-filter-schema
Open

rich7420 wants to merge 7 commits into
apache:mainfrom
rich7420:fix/4138-snapshot-filter-schema

Conversation

@rich7420

@rich7420 rich7420 commented Oct 26, 2026 •

Copy link
Copy Markdown

Closes #4138

Rationale for this change

Time-travel scans project the snapshot's schema but bind row filters to the current schema. Dropping and re-adding a same-named column therefore makes historical filters use the wrong field ID and silently return no rows.

Use the scan's full schema for file planning and Arrow filtering, including filter columns excluded from the output. Branch scans use the table's current schema for both filtering and projection, so an upsert inside a transaction sees staged schema changes. Tag scans keep the tag's snapshot schema. Partition inspection without an explicit snapshot continues to use the current schema.

Are these changes tested?

On Python 3.12, after merging main at fef852f4, make test PYTEST_ARGS='-q --tb=short' passes with 4,890 passed, 5 skipped and 129 deselected. make lint passes.

With pyiceberg/ reverted to main, the nine historical-read regression cases fail. Removing the branch check in TableScan._scan_schema makes eight cases fail: the two branch row-filter tests under each of the three catalogs, and both upsert tests. Restoring it makes all eight pass. The issue's standalone repro produces 50 rows with to_arrow() and a count of 50 with count(), instead of zero. Spark/Docker integration suites were not run.

Are there any user-facing changes?

Historical filters resolve names and field IDs using the snapshot's schema, matching projection. Names introduced after that snapshot raise a field lookup error. Ordinary and incremental scans retain their current-schema behavior. Branch scans now project the current schema instead of the branch head's snapshot schema. Upserts can also update matching rows after a non-key column is added in the same transaction.

Bind scan planning and Arrow filters to the same full schema as projection.
Keep current-schema binding for deletes and unpinned partition inspection.
Use the transaction schema for both filtering and projection so schema
changes do not bind upsert joins to an older branch snapshot. Share this
scan behavior with deletes and cover added or replaced join columns,
branch writes, staged writes, and updates after a staged schema change.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 05:53

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Preserve current-schema partition inspection alongside manifest-list
decryption. Bind the new residual-cache filter against the scan schema
so time-travel scans keep using the snapshot schema.
Preserve branch context when copying scans so schema changes do not make
branch filters read old field IDs or reject renamed columns. Tags and
explicit snapshot scans continue to use their historical schemas.
@rich7420
rich7420 marked this pull request as draft November 10, 2026 03:07
@rich7420
rich7420 marked this pull request as ready for review November 10, 2026 03:10
# Conflicts:
#	pyiceberg/table/__init__.py
#	tests/table/test_init.py
# Conflicts:
#	tests/table/test_inspect.py
…nd to

Main's apache#4400 finds list and map columns by looking up the filter's field
IDs in the current table schema. A time-travel filter is bound to the
snapshot's schema, so a column dropped since then raised "Could not find
field with id". Look the IDs up in the schema the filter is bound to.

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.

Time-travel scan binds row_filter to the current schema and returns no rows after a column is dropped and re-added

2 participants