zhuqi-lucas opened a new issue, #27908:
URL: https://github.com/apache/datafusion/issues/27908
### Is your feature request related to a problem or challenge?
A file group with several files that are each sorted, but overlap each
other, can't satisfy an ordering.
`FileScanConfig::try_sort_file_groups_by_statistics` only reorders files within
each group, so overlapping files keep the `SortExec`:
```text
SortExec: expr=[ticker ASC]
DataSourceExec: file_groups={1 group: [[a.parquet, b.parquet, c.parquet]]}
```
With one file per group, each partition is sorted and the sort becomes a
merge:
```text
SortPreservingMergeExec: [ticker ASC]
DataSourceExec: file_groups={3 groups: [[a.parquet], [b.parquet],
[c.parquet]]}
```
We hit this in a custom scan that packs several hive partitions into one
group in partition order, which serves time ordered TopK queries. A query
ordered by the file columns alone then sorts every row.
### Describe the solution you'd like
A narrow first step of #19724:
1. Allow `try_pushdown_sort` to return `Exact` with more partitions than the
input had, as long as each partition satisfies the ordering.
2. In the standalone `SortExec` path of `PushdownSort`, when the sort
required a single partition and the new input has several, put a
`SortPreservingMergeExec` with the sort's fetch on top instead of only removing
the sort. Today this path removes the sort without checking the partition count.
3. Optionally, let `FileScanConfig` split a group into one file per group
when its files overlap but each is sorted, capped by a limit on the number of
groups.
1 and 2 let custom sources do this. 3 brings it to the built-in file scans.
### Describe alternatives you've considered
Planning the scan with one file per group up front, e.g. with
`preserve_file_partitions`. That's static and applies to every query on the
table, while the best grouping depends on the query's ordering.
### Additional context
Related to #19724, which discusses re-arranging file groups more generally,
including the parallelism trade off. Part of #24270.
--
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]