fix(parquet): remap sorting columns for partitioned writes - #24211
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24211 +/- ##
==========================================
- Coverage 81.06% 81.05% -0.01%
==========================================
Files 1106 1106
Lines 382191 382245 +54
Branches 382191 382245 +54
==========================================
+ Hits 309807 309842 +35
- Misses 54095 54105 +10
- Partials 18289 18298 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jayzhan211
approved these changes
Aug 10, 2026
Member
Author
|
@jayzhan211 Thanks for the review! |
kosiew
pushed a commit
to kosiew/datafusion
that referenced
this pull request
Aug 12, 2026
) ## Which issue does this PR close? - Closes apache#24210. ## Rationale for this change When Hive partition columns are not kept in Parquet files, `FileSinkConfig::output_schema()` still describes the sink input while `get_writer_schema(&conf)` removes those partition columns. `ParquetFormat::create_writer_physical_plan` currently converts the input ordering directly to Parquet `sorting_columns`, so its column indices can reference removed columns or the wrong positions in the written schema. Reading that metadata can then panic in `SchemaDescriptor::column` with an out-of-bounds index. The execution ordering and the Parquet footer ordering have different schema domains: `DataSinkExec` must retain the original input ordering, while `ParquetSink` metadata must use indices from the actual writer schema. ## What changes are included in this PR? - Derive Parquet `sorting_columns` from both the input schema and `get_writer_schema(&conf)`. - Omit ordering keys that are removed from the written file, such as Hive partition columns. - Remap retained ordering keys to their writer-schema indices while preserving sort direction and null ordering. - Keep the original `order_requirements` unchanged for `DataSinkExec`. - Avoid writing an empty `sorting_columns` list when every ordering key is removed. - Add unit and end-to-end regression coverage for partitioned Parquet writes. ## Are these changes tested? Yes. The new tests cover the writer-schema remapping directly and verify the resulting Parquet footer after a partitioned write. ## Are there any user-facing changes? There are no public API changes. Newly written partitioned Parquet files now contain valid `sorting_columns` metadata based on their physical file schema. Existing files with invalid metadata are unchanged and must be rewritten separately.
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?
Rationale for this change
When Hive partition columns are not kept in Parquet files,
FileSinkConfig::output_schema()still describes the sink input whileget_writer_schema(&conf)removes those partition columns.ParquetFormat::create_writer_physical_plancurrently converts the input ordering directly to Parquetsorting_columns, so its column indices can reference removed columns or the wrong positions in the written schema. Reading that metadata can then panic inSchemaDescriptor::columnwith an out-of-bounds index.The execution ordering and the Parquet footer ordering have different schema domains:
DataSinkExecmust retain the original input ordering, whileParquetSinkmetadata must use indices from the actual writer schema.What changes are included in this PR?
sorting_columnsfrom both the input schema andget_writer_schema(&conf).order_requirementsunchanged forDataSinkExec.sorting_columnslist when every ordering key is removed.Are these changes tested?
Yes. The new tests cover the writer-schema remapping directly and verify the resulting Parquet footer after a partitioned write.
Are there any user-facing changes?
There are no public API changes. Newly written partitioned Parquet files now contain valid
sorting_columnsmetadata based on their physical file schema. Existing files with invalid metadata are unchanged and must be rewritten separately.