Skip to content

fix: preserve narrowing TRY_CAST comparison semantics - #24713

Draft
EltonChang1 wants to merge 4 commits into
apache:mainfrom
EltonChang1:codex/preserve-narrowing-try-cast
Draft

EltonChang1 wants to merge 4 commits into
apache:mainfrom
EltonChang1:codex/preserve-narrowing-try-cast

Conversation

@EltonChang1

@EltonChang1 EltonChang1 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

A narrowing TRY_CAST returns NULL for values outside the target integer range. Removing that cast from a comparison lets those values participate directly, so the same row can project NULL while its comparison incorrectly returns true.

What changes are included in this PR?

  • Add a shared integer-domain check covering smaller widths and signed/unsigned transitions.
  • Preserve narrowing integer TRY_CAST expressions in logical comparisons, IN lists, and the physical comparison simplifier used by pushed-down filters.
  • Cover integer boundaries, positive and negative overflow, NULL input, both operand orders, and signed-to-unsigned casts.
  • Add a Parquet regression with logical optimization disabled to exercise the physical simplifier independently.
  • Fix the SQL regression's duplicate projection names and Boolean result-type declaration.

What is the testing strategy for this PR?

The logical optimizer, physical expression, and integer-domain helper regressions pass locally. SQL tests matching cast.slt and parquet_filter_pushdown.slt also pass, including the isolated Parquet pushdown regression.

Full-workspace cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --all -- --check, and git diff --check pass locally.

The prescribed extended workspace test run also passes locally, including all 540 SQL files. The suite's existing ignored Rust tests were skipped.

Are there any user-facing changes?

Yes. Comparisons and IN predicates over narrowing integer TRY_CAST preserve NULL-on-overflow semantics, excluding out-of-range values from filters.

AI-assisted contribution disclosure

Prepared with AI assistance. Human review is still pending.

@alamb

alamb commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Hi -- what is the status of this PR?

@EltonChang1

Copy link
Copy Markdown
Contributor Author

I’ve fixed the SQL regression failures and expanded coverage for overflow/NULL semantics and Parquet pushdown. Fresh CI is running; I’ll mark this ready for review once it passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Narrowing try_cast is incorrectly unwrapped from comparisons, dropping NULL-on-overflow semantics

2 participants