Repository navigation
Commit 54a4bbf
fix: do not panic when displaying a Date64 scalar of i64::MIN (#26139)
## Which issue does this PR close?
- Closes #24892.
## Rationale for this change
`impl fmt::Display for ScalarValue` unwraps
`chrono::Duration::try_milliseconds(v)` in the `Date64` arm. That
returns `None` for `i64::MIN`, which `Duration` cannot represent, so
printing such a literal panics, for example `EXPLAIN SELECT
arrow_cast(-9223372036854775808, 'Date64')`.
#24893 proposed the same change and was closed as part of a batch of
PRs, not on its merits. This PR redoes it on current `main`.
## What changes are included in this PR?
`try_milliseconds` and `checked_add_signed` are chained with `and_then`,
so a value `Duration` cannot hold falls into the existing `None => ""`
branch. That's how the neighbouring out-of-range case already formats
(added for apache/arrow-rs#7728). One file, +7/-1.
## What is the testing strategy for this PR?
`test_display_date64_large_values` now also checks `i64::MIN` and
`i64::MAX`:
- Without the fix it panics at the same `unwrap` (`scalar/mod.rs:5651`).
- With the fix, `cargo test -p datafusion-common --lib` passes 623
tests, and `rustfmt --check` is clean.
`cargo clippy -p datafusion-common --all-targets -- -D warnings` fails
locally on an unused import in `config.rs:4157`. That happens on
unmodified `main` too, probably because I ran without the `parquet`
feature, so it's unrelated.
**Not verified:** the issue's second reproduction, a `RANGE` window
frame over a `Date64` column containing `i64::MIN`. I only ran the unit
test. If that path panics somewhere other than this `Display` impl, this
PR doesn't fix it.
## Are there any user-facing changes?
No panic: a `Date64` of `i64::MIN` displays as an empty string, like
other out-of-range dates.
**AI disclosure:** prepared with Claude Code (Claude Opus 5.5), which
wrote the change and the test and ran the commands above.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 03204c0 commit 54a4bbf
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5646 | 5646 | | |
5647 | 5647 | | |
5648 | 5648 | | |
5649 | | - | |
| 5649 | + | |
| 5650 | + | |
| 5651 | + | |
| 5652 | + | |
5650 | 5653 | | |
5651 | 5654 | | |
5652 | 5655 | | |
| |||
10127 | 10130 | | |
10128 | 10131 | | |
10129 | 10132 | | |
| 10133 | + | |
| 10134 | + | |
| 10135 | + | |
10130 | 10136 | | |
10131 | 10137 | | |
10132 | 10138 | | |
| |||
0 commit comments