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

   ### Describe the bug
   
   `date_trunc` can produce non-monotonic results across timezone transitions, 
but DataFusion treats it as order-preserving and may remove a required sort.
   
   ### To Reproduce
   
   ```sql
   SELECT
     arrow_cast(ts, 'Int64') AS input_epoch,
     arrow_cast(date_trunc('hour', ts), 'Int64') AS truncated
   FROM (
     SELECT
       arrow_cast(
         column1,
         'Timestamp(Second, Some("America/Goose_Bay"))'
       ) AS ts
     FROM (
       VALUES
         (562129260::bigint),
         (562129259::bigint)
     )
     ORDER BY ts
     LIMIT 2
   )
   ORDER BY date_trunc('hour', ts);
   ```
   
   DataFusion returns:
   
   ```text
   +-------------+-----------+
   | input_epoch | truncated |
   +-------------+-----------+
   | 562129259   | 562129200 |
   | 562129260   | 562125600 |
   +-------------+-----------+
   ```
   
   The `truncated` values are descending despite the requested ascending order.
   
   `EXPLAIN` shows that the plan contains the inner sort on `ts` but no sort on 
`date_trunc('hour', ts)`.
   
   ### Expected behavior
   
   The result should be ordered by the truncated timestamp:
   
   ```text
   +-------------+-----------+
   | input_epoch | truncated |
   +-------------+-----------+
   | 562129260   | 562125600 |
   | 562129259   | 562129200 |
   +-------------+-----------+
   ```
   
   `date_trunc` should only report ordered output when it is guaranteed to 
preserve ordering.
   
   ### Additional context
   
   Found while auditing `date_trunc` for #25344. Related to the timezone 
handling introduced in #9068.
   


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