EltonChang1 opened a new pull request, #24713: URL: https://github.com/apache/datafusion/pull/24713
## Which issue does this PR close? - Closes #24702. ## Rationale for this change A narrowing `TRY_CAST` can return `NULL` for source values outside the target integer range. Unwrapping that cast from a comparison made those values participate in the comparison directly, producing self-contradictory results such as a projected `NULL` alongside `TRY_CAST(...) > 1 = true`. ## What changes are included in this PR? - Add a shared signed/unsigned integer-domain check for narrowing casts. - Keep narrowing integer `TRY_CAST` expressions intact in logical binary and `IN`-list simplification. - Apply the same guard in physical comparison simplification used by pushed-down filters. - Add logical, physical, helper, and SQL regression coverage. Ordinary `CAST` behavior is unchanged. ## Are these changes tested? Yes. The following checks passed locally: - `cargo test -p datafusion-expr-common test_is_integer_narrowing_cast` - `CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0 cargo test -p datafusion-optimizer test_not_unwrap_narrowing_integer_try_cast` - `CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0 cargo test -p datafusion-physical-expr test_no_unwrap_narrowing_integer_try_cast` - `CARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0 cargo clippy -p datafusion-expr-common -p datafusion-optimizer -p datafusion-physical-expr --lib -- -D warnings` - `cargo fmt --all -- --check` - `git diff --check` The focused `cast.slt` case was not run locally because the workspace has about 3 GiB free and `protoc` is unavailable. It is included for CI; the two rewrite layers it exercises compile and pass their direct regression tests. ## Are there any user-facing changes? Yes. Comparisons and `IN` predicates over narrowing integer `TRY_CAST` expressions now preserve SQL `NULL`-on-overflow semantics instead of admitting out-of-range rows. ## AI-assisted contribution disclosure This change was prepared with AI assistance and has not yet received human review. The implementation was traced end-to-end across both affected simplifiers; the local SQL-test limitation is called out above. -- 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]
