haohuaijin opened a new issue, #26108:
URL: https://github.com/apache/datafusion/issues/26108

   ### Is your feature request related to a problem or challenge?
   
   Queries over ordered timestamp data can require an unnecessary sort after 
applying `to_timestamp_micros` or `to_unixtime`, even when these conversions 
preserve the input ordering.
   
   For example, given a table ordered by `micros ASC NULLS LAST`:
   
   ```sql
   SELECT to_unixtime(
       date_bin(
           INTERVAL '1 second',
           to_timestamp_micros(micros),
           TIMESTAMP '1970-01-01'
       )
   ) AS bucket
   FROM ordered_timestamps
   ORDER BY bucket ASC NULLS LAST;
   ```
   
   The conversion chain preserves ordering, but the resulting plan currently 
includes a `SortExec`.
   
   ### Describe the solution you'd like
   
   Allow DataFusion to propagate ordering through:
   
   - `to_timestamp_micros` with a single integer argument.
   - `to_unixtime` with a single integer, date, or timestamp argument.
   
   Preserve the input sort direction and NULL placement so redundant sorts can 
be removed.
   
   Precision reduction can produce equal output values, so sorting by 
additional keys must remain when their ordering cannot be established.
   
   ### Describe alternatives you've considered
   
   Keep the existing explicit sort. This produces correct results but performs 
unnecessary work when the converted values are already ordered.
   
   ### Additional context
   
   _No response_


-- 
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]

Reply via email to