Yibo-Dong opened a new issue, #27704:
URL: https://github.com/apache/datafusion/issues/27704
### Describe the bug
A Parquet file written by `COPY (... ORDER BY b) TO '...parquet'` is read
back with a declared output ordering on a different column (`a`) when a
multi-field struct column appears before `b` in the file schema. The planner
then removes the `SortExec` for `ORDER BY a`, and the query silently returns
rows that are not sorted.
### To Reproduce
Tested with `datafusion-cli` built from main at
`67fefd07a4ef4b7773bbcc284583b45cef4edc3f` (2026-11-24), default configuration.
The SQL writes its own file under a relative path.
```sql
COPY (
SELECT named_struct('x', i, 'y', i) AS st, i % 3 AS a, i AS b
FROM generate_series(1, 6) AS t(i)
ORDER BY b
) TO 'data/sorted_struct/f.parquet';
CREATE EXTERNAL TABLE t STORED AS PARQUET LOCATION 'data/sorted_struct/';
SELECT a, b FROM t ORDER BY a;
SELECT a, b FROM t ORDER BY a + 0;
EXPLAIN FORMAT INDENT SELECT a, b FROM t ORDER BY a;
```
Output:
```
-- SELECT a, b FROM t ORDER BY a;
+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 2 | 2 |
| 0 | 3 |
| 1 | 4 |
| 2 | 5 |
| 0 | 6 |
+---+---+
-- SELECT a, b FROM t ORDER BY a + 0;
+---+---+
| a | b |
+---+---+
| 0 | 3 |
| 0 | 6 |
| 1 | 1 |
| 1 | 4 |
| 2 | 2 |
| 2 | 5 |
+---+---+
-- EXPLAIN (physical plan; path shortened)
DataSourceExec: file_groups={1 group: [[.../data/sorted_struct/f.parquet]]},
projection=[a, b], output_ordering=[a@0 ASC NULLS LAST], file_type=parquet
```
The scan reports `output_ordering=[a@0 ASC NULLS LAST]` although the file
was written in `b` order, so no `SortExec` remains in the plan for `ORDER BY a`.
### Expected behavior
`SELECT a, b FROM t ORDER BY a` must return rows ordered by `a`, i.e. the
`a` column must read `0, 0, 1, 1, 2, 2` (the same as `ORDER BY a + 0` on the
same table, which keeps its sort). The file is sorted by `b`, so the scan
should declare `b ASC` (or no ordering), not `a ASC`.
### Additional context
_No response_
### Willingness to contribute
None
--
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]