TTyChud opened a new pull request, #27794: URL: https://github.com/apache/datafusion/pull/27794
## Which issue does this PR close? - Closes #27745. ## Rationale for this change Parquet's `SortingColumn.column_idx` counts leaf columns, but DataFusion wrote the top-level Arrow field index. A struct, list or map before the sort key shifts it onto another column. With `payload STRUCT<a, b>, b, id` written `WITH ORDER (id ASC)`, the file says it is sorted by leaf 2: the top-level `b`. DataFusion trusts that ordering when it reads the file back, so `SELECT b, id FROM t ORDER BY b` returns `b` as 30, 20, 10. The read side has a related problem. It matches the leaf by name against the top-level fields, so `payload.b` can match `b`. ## What changes are included in this PR? In `datafusion/datasource-parquet/src/metadata.rs`: - `lex_ordering_to_sorting_columns` writes the leaf index, using `LeafResolver`. A nested sort key ends the list; Parquet has no way to mark it sorted, and the keys after it aren't sorted by themselves. Partition columns are skipped as before. I folded `sort_expr_to_sorting_column` into it. - `sorting_columns_to_physical_exprs` only accepts top-level leaves, and stops at the first sorting column it can't resolve (it used to skip it). A negative or out-of-range `column_idx` no longer panics. Files written before this fix keep their bad index. The reader now ignores one that points at a nested leaf, but it can't detect one that lands on another top-level column, like the example above. ## What is the testing strategy for this PR? - `test_sorting_columns_after_struct_round_trip` in `datafusion/core/tests/parquet/ordering.rs` writes the table above and reads it back through a table without `WITH ORDER`. It fails on main. - Unit tests in `metadata.rs` for both directions. ## Are there any user-facing changes? Queries over Parquet files sorted on a column after a nested column keep their sort. No public API changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
