Skip to content

fix(arrow): use Parquet leaf indices for projection - #3624

Open
darshpatel1052 wants to merge 4 commits into
apache:mainfrom
darshpatel1052:fix/3609-parquet-schema-projection
Open

darshpatel1052 wants to merge 4 commits into
apache:mainfrom
darshpatel1052:fix/3609-parquet-schema-projection

Conversation

@darshpatel1052

Copy link
Copy Markdown

Which issue does this PR close?

What changes are included in this PR?

This PR fixes incorrect Parquet column projection and predicate lookup caused by relying on Arrow's leaf numbering, which can differ from the actual Parquet column order for nested types such as ListView and LargeListView.

The changes include:

  • Parquet-based column indexing: Resolve field IDs to leaf indices using the Parquet schema instead of Fields::filter_leaves, ensuring projection masks select the correct physical columns.
  • Name mapping: Replace Arrow-based leaf index mapping with a recursive Parquet schema walk. Handle nested structs, maps, and different Parquet list encodings, including legacy repeated-field layouts.
  • Predicate pushdown: Use Parquet-derived field ID mappings for predicate evaluation, row-group statistics, bloom filters, and page-index filtering.
  • Nested list views: Recursively traverse ListView and LargeListView elements during schema mapping and projected-field collection.
  • Missing columns: Remove the fallback to ProjectionMask::all() when no requested columns exist in the file. This prevents unrelated file values from being returned under newly added column names.
  • Zero-column batches: Preserve the original row count when transforming batches with no physical columns, allowing missing fields to be populated with NULLs or initial defaults.
  • Partially annotated schemas: Allow Parquet schemas containing both ID-bearing and ID-less leaves without discarding valid field ID mappings.

Are these changes tested?

Added and extended regression tests covering:

  • test_projection_after_nested_list_view: Tests nested lists with multiple element leaves, including regular/large lists and list views, with embedded field IDs and name mapping. Covers projection and predicate filtering through row-group, bloom-filter, and page-index configurations.
  • test_name_mapping_parquet_list_encodings: Verifies correct leaf indices across different Parquet list encodings, including legacy repeated fields.
  • test_schema_evolution_add_column: Verifies that existing data is preserved while missing columns return NULLs or their configured initial defaults, including projections containing only absent fields.
  • Extended name-mapping tests for nested fields, unmapped fields, and duplicate aliases.

The reader-level regression tests also exercise the related pipeline and record-batch transformation changes.

AI Disclosure

OpenAI Codex (GPT-6.1 Sol, xhigh reasoning effort) assisted with regression-test development, and code review. I reviewed the resulting changes and take responsibility for their correctness.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 06:18

Copilot AI left a comment

Copy link
Copy Markdown

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. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical reader and projection defects remain for partially ID-annotated schemas and legacy two-level maps, which can select wrong or missing columns and break predicate resolution.

3 open issues

Review effort: Lite

@JeonDaehong JeonDaehong 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.

I checked the missing-column side of this, since dropping the ProjectionMask::all() fallback changes what gets read when every projected column is absent. Projecting only a column the file doesn't have, with positional deletes ([1] and [0,2]), a filter on a present column, both, and b IS NULL, on one and on three row groups: row counts and the all-null values match main in every case, and the reader tests pass.

@darshpatel1052

Copy link
Copy Markdown
Author

Merged the latest main and resolved the conflicts with the recent struct presence (#3438) and variant support (#2880) changes.

The Parquet leaf-index mapping is preserved, along with the missing-column projection behavior. I also reran the full iceberg test suite, formatting checks, and Clippy locally, all passing.

Thanks @JeonDaehong for checking the missing-column cases as well!

@JeonDaehong JeonDaehong 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.

Re-ran the missing-column checks on 619cb88 after the merge with #3438. Projecting only b, which the file doesn't have, gives the same rows as main in every case: with positional deletes [1] and [0,2], a > 2, b IS NULL and b IS NOT NULL, on 1 and 3 row groups. The arrow:: tests, including the struct presence ones, pass too. LGTM, thanks @darshpatel1052!

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.

Projection: select Parquet columns by Parquet schema path, not by Arrow leaf numbering

3 participants