[SPARK-59609][SQL] Fix Parquet/ORC aggregate push-down reading statistics from the wrong column - #58945
Open
hemanthboyina wants to merge 2 commits into
Open
[SPARK-59609][SQL] Fix Parquet/ORC aggregate push-down reading statistics from the wrong column#58945hemanthboyina wants to merge 2 commits into
hemanthboyina wants to merge 2 commits into
Conversation
…tics from the wrong column
tdcmeehan
suggested changes
Sep 22, 2026
| // Resolve by name in the file's own schema; a positional lookup breaks under mergeSchema. | ||
| val fileSchema = footerFileMetaData.getSchema | ||
| def fileFieldIndex(colName: String): Int = | ||
| if (fileSchema.containsField(colName)) fileSchema.getFieldIndex(colName) else -1 |
There was a problem hiding this comment.
It seems we don't check case sensitivity here. If so, I believe we need to pass down that flag, same as the ORC reader.
Contributor
Author
There was a problem hiding this comment.
done, fixed it now
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.
What changes were proposed in this pull request?
When aggregate push-down is enabled, Spark answers MIN/MAX/COUNT from a file's footer statistics instead of reading the data. To locate a column's statistics it used the column's position in the read schema, then applied that position to the file's physical columns. This is only correct when every file's layout matches the read schema. This PR resolves the column against each file's own schema instead:
for Parquet, it looks the column up by name in the file's footer schema;
for ORC, it resolves the column to its position in the file's own schema, following the same name/positional rules ORC already uses in requestedColumnIds.
If a file does not contain the column,
MIN/MAXreturnnullandCOUNT(col)counts no non-null values, instead of reading the wrong column.Why are the changes needed?
The old position-based lookup silently returns wrong results when a file's column layout differs from the read schema, e.g. Parquet with mergeSchema=true where some files are missing the column, or ORC files with a different column order.
Does this PR introduce any user-facing change?
Yes. With aggregate push-down enabled (spark.sql.parquet.aggregatePushdown / spark.sql.orc.aggregatePushdown, both false by default), the queries above now return correct results instead of silently wrong ones.
How was this patch tested?
Added tests to FileSourceAggregatePushDownSuite (Parquet mergeSchema with a missing column; ORC with a different column order), run with the vectorized reader on and off. Both fail before the fix and pass after. All existing push-down suites still pass.
Was this patch authored or co-authored using generative AI tooling?
Yes, used Claude code