Skip to content

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

Merged
adriangb merged 2 commits intoapache: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 intoapache:mainfrom
pydantic:fix-parquet-leaf-index-struct-cols

Conversation

@friendlymatthew
Copy link
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-actions github-actions bot added the datasource Changes to the datasource crate label Mar 4, 2026
Copy link
Contributor Author

@friendlymatthew friendlymatthew left a comment

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
Contributor Author

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

Copy link
Contributor

@adriangb adriangb left a comment

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
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-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Mar 4, 2026
@friendlymatthew friendlymatthew force-pushed the fix-parquet-leaf-index-struct-cols branch from 5561691 to 29f6891 Compare March 5, 2026 01:59
@adriangb adriangb added this pull request to the merge queue Mar 5, 2026
Merged via the queue into apache:main with commit 27c9cda Mar 5, 2026
30 checks passed
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 sqllogictest SQL 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