Commit 0512962
authored
fix date_trunc overflows converting extreme non-ns timestamps to nanoseconds (#22262)
## Which issue does this PR close?
- Closes #22209
## Rationale for this change
`date_trunc` can panic during planning and constant folding when it
receives extreme non-nanosecond timestamps. The overflow happens while
converting values to nanoseconds, so a valid SQL query can crash the
planner instead of returning a proper error. This change makes that path
fail gracefully with a planning error.
## What changes are included in this PR?
- Adds overflow checks to the timestamp scale conversion used by
`date_trunc`.
- Converts the panic into a normal out-of-range planning error.
- Adds regression coverage for extreme `Timestamp(Second)`,
`Timestamp(Millisecond)`, and `Timestamp(Microsecond)` inputs.
- Adds a SQL-level regression test for the `arrow_cast(...)` plus
`date_trunc(...)` repro.
## Are these changes tested?
- Yes. I added regression tests and verified the repro now returns an
error instead of panicking.
## Are there any user-facing changes?
- Yes. Out-of-range timestamp inputs now produce a planning error rather
than aborting the query with a panic.1 parent 1a61a59 commit 0512962
2 files changed
Lines changed: 13 additions & 1 deletion
File tree
- datafusion
- functions/src/datetime
- sqllogictest/test_files/datetime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
721 | | - | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
722 | 728 | | |
723 | 729 | | |
724 | 730 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2428 | 2428 | | |
2429 | 2429 | | |
2430 | 2430 | | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
2431 | 2437 | | |
2432 | 2438 | | |
2433 | 2439 | | |
| |||
0 commit comments