Toby1009 opened a new pull request, #25668:
URL: https://github.com/apache/datafusion/pull/25668

   ## Which issue does this PR close?
   
   Closes #25667.
   
   ## Rationale for this change
   
   Compositions such as nested `date_trunc` or `CAST(trunc(x) AS REAL)` can 
retain redundant sorts even when their inputs are ordered. Scalar UDFs using 
the default bounds implementation lose their output type during property 
analysis, although `ScalarFunctionExpr` already knows the resolved return type.
   
   This implements the central fallback discussed in [the review of 
#25575](https://github.com/apache/datafusion/pull/25575#issuecomment-5797397833).
   
   ## What changes are included in this PR?
   
   - In `ScalarFunctionExpr::get_properties`, replace an unbounded `Null` 
result with a typed unbounded interval using the resolved return type. Preserve 
explicit bounds and UDF evaluation errors; retain the original interval if the 
fallback type is unsupported.
   - Remove the type-only `evaluate_bounds` overrides for `date_bin` and 
`from_unixtime`, and document the central behavior for UDF authors.
   - Keep the `PhysicalExpr::evaluate_bounds` delegation unchanged, without 
adding a fallback to the constraint solver. Removing the two overrides means 
their direct bounds evaluation returns the default `Null` interval again.
   - Include two equivalent benchmark cleanups required by strict Clippy: a 
boolean-to-integer conversion and a local type alias.
   
   ## What is the testing strategy for this PR?
   
   Unit tests cover resolved output types, explicit and session timezones, 
unsupported interval types, preservation of existing bounds and errors, and 
separation from direct bounds evaluation. Removing the fallback makes the new 
type-recovery tests fail.
   
   SQL tests cover redundant sort removal for nested datetime functions and a 
numeric UDF followed by a cast, including NULL input. Negative plan and result 
tests retain the required sorts for named timezone transitions and time-of-day 
arithmetic across midnight. Existing `date_bin` and `from_unixtime` plan tests 
remain unchanged.
   
   Validation:
   
   - Extended workspace test suite, including SQL logic tests.
   - `cargo fmt --all`.
   - `cargo clippy --all-targets --all-features -- -D warnings`.
   - `uv run ./dev/rust_lint.sh`.
   
   A local planning experiment against the base `main` commit used the same 
sorted 100-row `MemTable`, 20 warmups and 200 planning iterations, with three 
alternating runs of each build. The nested datetime and numeric-cast queries 
each removed one redundant sort and returned identical results. Median planning 
times were 679 → 645 µs and 585 → 553 µs; control and struct-return queries 
were essentially unchanged. These are small local measurements using the 
unoptimized `ci` profile, not production execution-speed claims.
   
   ## Are there any user-facing changes?
   
   Safe compositions of scalar functions can avoid redundant sorts without 
individual UDFs implementing bounds solely to preserve their output type. 
Existing ordering rules still determine whether a sort can be removed. No 
public API signatures or FFI structures change.
   


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