Skip to content

correct parquet leaf index mapping when schema contains struct cols - #20698

Merged
adriangb merged 2 commits into
apache:mainfrom
pydantic:fix-parquet-leaf-index-struct-cols
Mar 5, 2026
Merged

correct parquet leaf index mapping when schema contains struct cols#20698
adriangb merged 2 commits into
apache:mainfrom
pydantic:fix-parquet-leaf-index-struct-cols

Conversation

@friendlymatthew

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Row filter pushdown assumed Arrow field indices equal Parquet leaf indices, which breaks when Struct columns are present because their children expand into separate leaves and shift all subsequent indices

@github-actionsgithub-actionsBot added the datasource Changes to the datasource crate label Mar 4, 2026

@friendlymatthewfriendlymatthew left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

self review

Comment on lines -442 to -445
// For primitive-only columns, root indices ARE the leaf indices
if nested == NestedColumnSupport::PrimitiveOnly {
return root_indices.to_vec();
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Just because a filter only references primitive columns doesn't mean Arrow indices equal Parquet leaf indices.

Struct columns elsewhere in the schema still shift the leaf numbering. The enum encoded the wrong signal (and was only used here), so I removed it and always do the proper mapping

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

This makes sense to me. Could we add an SLT test?

Comment on lines +416 to +420
// Always map root (Arrow) indices to Parquet leaf indices via the schema
// descriptor. Arrow root indices only equal Parquet leaf indices when the
// schema has no group columns (Struct, Map, etc.); when group columns
// exist, their children become separate leaves and shift all subsequent
// leaf indices.

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.

Suggested change
// Always map root (Arrow) indices to Parquet leaf indices via the schema
// descriptor. Arrow root indices only equal Parquet leaf indices when the
// schema has no group columns (Struct, Map, etc.); when group columns
// exist, their children become separate leaves and shift all subsequent
// leaf indices.
// Always map root (Arrow) indices to Parquet leaf indices via the schema
// descriptor. Arrow root indices only equal Parquet leaf indices when the
// schema has no group columns (Struct, Map, etc.); when group columns
// exist, their children become separate leaves and shift all subsequent
// leaf indices.
// Struct columns are unsupported.

@github-actionsgithub-actionsBot added the sqllogictest SQL Logic Tests (.slt) label Mar 4, 2026
@friendlymatthew
friendlymatthewforce-pushed the fix-parquet-leaf-index-struct-cols branch from 5561691 to 29f6891CompareMarch 5, 2026 01:59
@adriangb
adriangb added this pull request to the merge queueMar 5, 2026
Merged via the queue into apache:main with commit 27c9cdaMar 5, 2026
30 checks passed
alamb pushed a commit to alamb/datafusion that referenced this pull request Mar 11, 2026
…pache#20698)
## Which issue does this PR close?
- Closesapache#20695
## Rationale for this change
Row filter pushdown assumed Arrow field indices equal Parquet leaf
indices, which breaks when Struct columns are present because their
children expand into separate leaves and shift all subsequent indices
alamb added a commit that referenced this pull request Mar 12, 2026
…truct cols (#20698) (#20884)
- Part of #19692
- Closes#20695 on branch-53
This PR:
- Backports #20698 from
@friendlymatthew to the branch-53 line
Co-authored-by: Matthew Kim <38759997+friendlymatthew@users.noreply.github.com>
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
…pache#20698)
## Which issue does this PR close?
- Closesapache#20695
## Rationale for this change
Row filter pushdown assumed Arrow field indices equal Parquet leaf
indices, which breaks when Struct columns are present because their
children expand into separate leaves and shift all subsequent indices
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasourceChanges to the datasource cratesqllogictestSQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

leaf_indices_for_roots returns wrong Parquet leaf indices when schema contains Struct columns

2 participants

@friendlymatthew@adriangb