Skip to content

fix: do not panic when displaying a Date64 scalar of i64::MIN - #24893

Draft
edubraqd wants to merge 1 commit into
apache:mainfrom
edubraqd:fix/date64-display-unwrap
Draft

fix: do not panic when displaying a Date64 scalar of i64::MIN#24893
edubraqd wants to merge 1 commit into
apache:mainfrom
edubraqd:fix/date64-display-unwrap

Conversation

@edubraqd

@edubraqd edubraqd commented Sep 3, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ScalarValue::Date64 formatting unwraps chrono::Duration::try_milliseconds, which is None for i64::MIN. Printing such a literal, for example EXPLAIN SELECT arrow_cast(-9223372036854775808, 'Date64'), panics instead of producing a plan.

What changes are included in this PR?

Chain try_milliseconds and checked_add_signed with and_then, so a value that chrono::Duration cannot hold is treated the same as a date that is out of range: it formats as an empty string, which is what the existing out-of-range handling (added for apache/arrow-rs#7728) already does.

Are these changes tested?

Yes. test_display_date64_large_values now also covers i64::MIN (which used to panic) and i64::MAX.

Are there any user-facing changes?

No panic when a Date64 literal of i64::MIN is displayed.

`ScalarValue::Date64` formatting unwrapped `chrono::Duration::try_milliseconds`,
which returns `None` for `i64::MIN` because that value is below the range
`chrono::Duration` can represent. Any plan that prints such a literal, for
example `EXPLAIN SELECT arrow_cast(-9223372036854775808, 'Date64')`, panicked
with "called `Option::unwrap()` on a `None` value".

Chain the two fallible steps instead so an unrepresentable date formats as an
empty string, the same way an out-of-range epoch offset already does.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the common Related to common crate label Sep 3, 2026
@edubraqd
edubraqd marked this pull request as draft September 4, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Displaying a Date64 scalar of i64::MIN panics

1 participant