Skip to content

refactor: de-duplicate parquet read plan construction#23426

Merged
adriangb merged 2 commits into
apache:mainfrom
pydantic:projection-read-plan-root-helper
Jul 10, 2026
Merged

refactor: de-duplicate parquet read plan construction#23426
adriangb merged 2 commits into
apache:mainfrom
pydantic:projection-read-plan-root-helper

Conversation

@adriangb

@adriangb adriangb commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Two independent commits, each green on its own; best reviewed commit by commit.

Rationale for this change

@mbutrovich spotted two pieces of duplication in projection_read_plan.rs while reviewing #23396, both deferred out of that (move-only) PR:

  1. build_projection_read_plan has three early-return paths — the all-plain-columns fast path, the no-struct-columns fast path, and the no-struct-accesses fallback. Each repeated the same ProjectionMask::roots + Schema::project + construct-ParquetReadPlan sequence.

  2. build_projection_read_plan and row_filter::build_parquet_read_plan both end in the same chain to build a leaf-level plan:

    leaf_indices_for_roots → resolve_struct_field_leaves → extend/sort/dedup
        → ProjectionMask::leaves → build_filter_schema → ParquetReadPlan
    

    They differ only in that the row filter also sizes the resulting leaves (required_bytes) and returns an Option.

What changes are included in this PR?

Commit 1 — root_level_plan: a new private helper taking sorted, deduplicated root indices and decoding every leaf below each root. The three early-return paths delegate to it. Net −9 lines.

Commit 2 — assemble_read_plan: shared by both callers. It returns the ParquetReadPlan plus the resolved leaf indices, which is what lets the row filter keep computing required_bytes without duplicating leaf resolution. build_parquet_read_plan shrinks from ~30 lines to ~10. leaf_indices_for_roots, resolve_struct_field_leaves and build_filter_schema become private to projection_read_plan, since assemble_read_plan is now their only caller.

No behavior change in either commit.

Are these changes tested?

Yes, by existing tests: datafusion-datasource-parquet unit tests (158 pass) and the parquet_integration suite in datafusion (213 pass), both unchanged and both green at each commit. The row-filter path touched by commit 2 is covered by parquet::filter_pushdown and the struct-field pushdown tests in row_filter.rs.

Are there any user-facing changes?

No.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BsRGsN18YBCji5iFTQmWpr

@github-actions github-actions Bot added the datasource Changes to the datasource crate label Jul 9, 2026
@adriangb adriangb force-pushed the projection-read-plan-root-helper branch from 81050bb to 653a70b Compare July 9, 2026 17:30
@adriangb

adriangb commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

cc @xudong963 @mbutrovich

@adriangb adriangb changed the title refactor: collapse repeated root-level parquet read plan construction refactor: de-duplicate parquet read plan construction Jul 9, 2026
adriangb and others added 2 commits July 9, 2026 19:25
`build_projection_read_plan` had three copies of the same
`ProjectionMask::roots` + `Schema::project` + `ParquetReadPlan`
sequence, one per early-return path. Extract `root_level_plan`.

No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BsRGsN18YBCji5iFTQmWpr
`build_projection_read_plan` and `row_filter::build_parquet_read_plan`
ran the same chain to build a leaf-level plan: leaf_indices_for_roots,
resolve_struct_field_leaves, sort/dedup, ProjectionMask::leaves,
build_filter_schema. They differed only in the row filter also sizing
the leaves and returning an Option.

Extract `assemble_read_plan`, which returns the plan plus the resolved
leaf indices so the row filter can compute `required_bytes` from them.
The three helpers it subsumes are now private to the module.

No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BsRGsN18YBCji5iFTQmWpr
@adriangb adriangb force-pushed the projection-read-plan-root-helper branch from 179f349 to 022f665 Compare July 9, 2026 19:26
@adriangb adriangb added this pull request to the merge queue Jul 10, 2026
Merged via the queue into apache:main with commit b9968a0 Jul 10, 2026
36 checks passed
@adriangb adriangb deleted the projection-read-plan-root-helper branch July 10, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants