You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support Date32/Date64 in unwrap_cast optimization (#21665)
## Which issue does this PR close?
N/A
## Rationale for this change
Filters like `WHERE EventDate >= '2013-07-01'` on a `UInt16` column
exposed as `Date32` via a view produce `CAST(CAST(EventDate AS Int32) AS
Date32) >= Date32("2013-07-01")` — 4 CAST operations per row. The
existing `unwrap_cast_in_comparison` optimizer can eliminate these but
didn't support `Date32`/`Date64`.
## What changes are included in this PR?
Add `Date32`/`Date64` to `is_supported_numeric_type` and the match arms
in `try_cast_numeric_literal`. They are treated like `Int32`/`Int64`
since that's their physical representation (days / ms since epoch).
A guard prevents Date↔Timestamp unwrapping, which is lossy (drops
time-of-day).
**ClickBench Q36-Q42 before:**
```
FilterExec: CAST(CAST(EventDate@0 AS Int32) AS Date32) >= 2013-07-01
AND CAST(CAST(EventDate@0 AS Int32) AS Date32) <= 2013-07-31
```
**After:**
```
FilterExec: EventDate@0 >= 15887 AND EventDate@0 <= 15917
```
## Are these changes tested?
Existing `casts` tests pass. ClickBench sqllogictest expectations
updated.
## Are there any user-facing changes?
No.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
0 commit comments