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

   ## Which issue does this PR close?
   
   - Closes #27689.
   
   ## Rationale for this change
   
   `TRY_CAST` returns `NULL` when a value overflows the target type. Unwrapping 
that cast from a comparison lets the overflowing source value produce `TRUE` or 
`FALSE` instead, which can make a `WHERE` clause keep a row that should be 
filtered out.
   
   ## What changes are included in this PR?
   
   - Preserve overflow-prone `TRY_CAST` expressions during logical comparison 
and `IN`-list rewrites.
   - Preserve them in the physical comparison simplifier as well, so 
pushed-down filters keep the same NULL behavior.
   - Cover timestamp widening and integer/decimal casts whose target cannot 
represent the full source range.
   - Keep strict `CAST` rewrites unchanged.
   
   ## What is the testing strategy for this PR?
   
   - Added optimizer and physical-expression regression tests for timestamp and 
decimal overflow.
   - Added SQL regressions for the reported seconds-to-nanoseconds and 
bigint-to-decimal cases, including the filtered rows.
   - `cargo test --profile ci -p datafusion-optimizer --lib 
'cast_preimage::tests::test_try_cast'`
   - `cargo test --profile ci -p datafusion-physical-expr --lib 
'simplifier::unwrap_cast::tests::test_no_unwrap_try_cast'`
   - `cargo test --profile ci -p datafusion-sqllogictest --test sqllogictests 
-- simplify_expr.slt`
   - `cargo clippy --profile ci -p datafusion-expr-common -p 
datafusion-optimizer -p datafusion-physical-expr --all-targets --features 
datafusion-optimizer/recursive_protection,datafusion-physical-expr/recursive_protection
 -- -D warnings`
   - `cargo fmt --all -- --check` and `git diff --check`
   
   The full-workspace clippy and extended test commands were attempted but 
could not complete in this environment because CMake and `protoc` are missing; 
the targeted checks above pass.
   
   ## Are there any user-facing changes?
   
   Yes. Comparisons and filters over overflowing `TRY_CAST` values preserve 
`NULL` and no longer treat those values as matching rows.
   
   ## AI-assisted contribution disclosure
   
   Prepared with AI assistance. Human review is welcome; I will work with 
reviewers to understand and address feedback.
   


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