fix: build_fallback_field_id_map produces incorrect column indices for schemas with nested types#2307
Open
mbutrovich wants to merge 6 commits intoapache:mainfrom
Open
fix: build_fallback_field_id_map produces incorrect column indices for schemas with nested types#2307mbutrovich wants to merge 6 commits intoapache:mainfrom
mbutrovich wants to merge 6 commits intoapache:mainfrom
Conversation
blackmwk
reviewed
Apr 1, 2026
This was referenced Apr 1, 2026
blackmwk
reviewed
Apr 2, 2026
Contributor
blackmwk
left a comment
There was a problem hiding this comment.
Thanks @mbutrovich for this fix! Generally LGTM!
Collaborator
Author
|
Most recent changes:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
What changes are included in this PR?
build_fallback_field_id_mapiterated over Parquet leaf columns instead of top-level fields when building the field ID to column index mapping for migrated files (no embedded field IDs). When nested types (struct, list, map) precede a primitive column, they expand into multiple leaves, causing the mapping to diverge fromadd_fallback_field_ids_to_arrow_schemawhich correctly assigns ordinal IDs to top-level Arrow fields. This made predicates on columns after nested types resolve to a leaf inside the group, crashing with "Leaf columnidin predicates isn't a root column in Parquet schema".The fix iterates
root_schema().get_fields()directly, assigning ordinal IDs only to top-level fields. For non-primitive fields (struct/list/map), it usesget_column_root_idxto advance past their leaf columns. This mirrors iceberg-java'sParquetSchemaUtil.addFallbackIds(), which iteratesfileSchema.getFields()assigning ordinal IDs to top-level fields.Also renames "Leave column" to "Leaf column" in error messages.
Are these changes tested?
An integration test (
test_predicate_on_migrated_file_with_nested_types) writes a Parquet file without field IDs containing struct, list, and map columns before anidcolumn, then reads with a predicate onid. This reproduces the exact crash before the fix. Test data is constructed withserde_arrowfor readability.Apache DataFusion Comet used the repro test in
apache/datafusion-comet#3860 and it passes with this change:
test: [DO NOT MERGE] test upstream iceberg-rust fix for #3860 datafusion-comet#3872