haohuaijin opened a new pull request, #25531: URL: https://github.com/apache/datafusion/pull/25531
## Which issue does this PR close? Closes #25523. Related to #25407. ## Rationale for this change A filter on a cast can incorrectly make its input appear constant and remove a required sort. For example, `CAST(x AS INT) = 0` matches both -0.5 and 0.5, but casting the singleton result interval back to DOUBLE yields [0.0, 0.0]. The optimizer can then return the wrong order for `ORDER BY x DESC`. ## What changes are included in this PR? Gate reverse Cast constraint propagation through a common allowlist for all types. Preserve propagation for conversions recognized by `check_bigger_cast`, integer-to-integer casts, and Float32-to-Float64 casts. For other conversions, keep the existing input range instead of treating a cast back as an inverse. The conservative allowlist may reduce range refinement and pruning for safe conversions that are not yet recognized. Runtime CAST behavior and forward interval evaluation are unchanged. ## What is the testing strategy for this PR? - Extend existing `cast.slt` with float-to-integer, integer-to-Float32, timestamp-to-date, and string-to-integer cases. The first three reproduce incorrect sort elimination before the corresponding guards; the string case checks compatibility. - Add a table-driven test for permitted and rejected reverse propagation paths. - Check Float32 widening against actual Cast results at NaN, infinity, signed zero, subnormal, and rounding boundaries. - Passed 24 Cast unit tests (one existing test ignored), 46 filter tests, and four relevant SLT files. ## Are there any user-facing changes? Queries retain required sorting when cast constraints cannot safely determine the input range. 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]
