Skip to content

Fix filtering on identity partition columns outside the scan projection - #4082

Open
ooreally wants to merge 1 commit into
apache:mainfrom
ooreally:fix-identity-partition-filter-projection
Open

ooreally wants to merge 1 commit into
apache:mainfrom
ooreally:fix-identity-partition-filter-projection

Conversation

@ooreally

@ooreally ooreally commented Oct 6, 2026

Copy link
Copy Markdown

Rationale for this change

When an identity partition column is absent from a Parquet file and excluded from selected_fields, filtering on that column can return an empty result even when its manifest partition value matches the predicate.

For example, a file containing other_field = ["foo", "bar", "baz"] with manifest partition partition_id = 1 should return all three rows for:

table.scan(row_filter="partition_id = 1", selected_fields=("other_field",)).to_arrow()

Resolve missing identity partition values using the existing union of output and filter field IDs before translating the Arrow filter.

Are these changes tested?

The existing identity partition projection tests now cover name-mapped Parquet files and files written by PyIceberg with embedded field IDs, one and multiple partitions, mixed partition/data predicates, partial projections, and zero, empty-string, and null partition values. Six regression cases fail on the original code; all seven focused cases pass with the fix.

Validation on Python 3.13.11 and PyArrow 25.0.1:

  • make test PYTEST_ARGS="-q --tb=short": 4,253 passed, 7 skipped, 126 deselected.
  • make lint: all repository-wide hooks passed.
  • Arrow and expression visitor unit suites: 284 passed, 3 skipped.
  • git diff --check: passed.

Are there any user-facing changes?

Yes. Scans that filter on identity partition columns omitted from both the physical file and the output projection now return the matching rows while preserving the requested output columns.

AI assistance: OpenAI Codex assisted with investigation, implementation, and local validation.

Resolve manifest partition values for filter fields as well as output fields so scans with narrow projections keep matching rows. Cover name-mapped and field-ID Parquet files and falsy partition values.
Comment thread pyiceberg/io/pyarrow.py
"""Apply Column Projection rules to File Schema."""
project_schema_diff = projected_schema.field_ids.difference(file_project_field_ids)
"""Resolve missing identity partition values for output and filter columns."""
project_schema_diff = projected_field_ids.difference(file_project_field_ids)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this is no longer derived from the projected schema, maybe rename to match the new param?

Suggested change
project_schema_diff = projected_field_ids.difference(file_project_field_ids)
missing_field_ids = projected_field_ids.difference(file_project_field_ids)

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