Toby1009 opened a new pull request, #25526: URL: https://github.com/apache/datafusion/pull/25526
## Which issue does this PR close? - Closes #25506. ## Rationale for this change `ORDER BY CAST(ts AS TIME)` can return incorrectly ordered results when an already ordered timestamp input crosses midnight. A named timezone rollback can similarly make a timestamp-to-date conversion non-monotonic. In both cases, DataFusion may incorrectly reuse the input ordering and remove the sort required by the cast result. ## What changes are included in this PR? Replace the broad temporal-to-temporal ordering rule with an explicit list of order-preserving temporal casts. Keep the existing lossless cast check separate because it provides the stronger guarantees used for strict ordering and statistics propagation. Cast expressions that may turn conversion failures into NULL no longer propagate ordering unless the conversion is known to be lossless, since a new NULL can violate `NULLS FIRST` or `NULLS LAST`. ## What is the testing strategy for this PR? The unit tests cover safe and unsafe temporal cast combinations, both sort directions, both NULL placements, unknown input types, and NULL-on-failure casts. The cases added to `cast.slt` cover timestamp-to-time conversion across midnight, timestamp-to-date conversion across a named timezone rollback, and verify that reducing timestamp precision still avoids an unnecessary sort. ## Are there any user-facing changes? Queries that order by a non-monotonic temporal cast now retain the required sort and return correctly ordered results. There are 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]
