From dc193aca1855b98c4b2dac0b99f1ffa8ff17b861 Mon Sep 17 00:00:00 2001 From: geographybuff Date: Thu, 8 Oct 2026 13:47:44 +0000 Subject: [PATCH] fix: do not panic when displaying a Date64 scalar of i64::MIN `Duration::try_milliseconds` returns `None` for `i64::MIN`, and the Date64 arm of `impl Display for ScalarValue` unwrapped it. Chain it with `checked_add_signed` so a value `Duration` cannot hold formats as an empty string, like an out-of-range date already does. Closes #24892 Co-Authored-By: Claude Opus 5.5 --- datafusion/common/src/scalar/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs index 37ae21d90d986..a0b42b4e42931 100644 --- a/datafusion/common/src/scalar/mod.rs +++ b/datafusion/common/src/scalar/mod.rs @@ -5646,7 +5646,10 @@ impl fmt::Display for ScalarValue { f, e.map(|v| { let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap(); - match epoch.checked_add_signed(Duration::try_milliseconds(v).unwrap()) + // `try_milliseconds` is `None` for `i64::MIN`, which + // `Duration` cannot hold: treat it as out of range too + match Duration::try_milliseconds(v) + .and_then(|d| epoch.checked_add_signed(d)) { Some(date) => date.to_string(), None => "".to_string(), @@ -10127,6 +10130,9 @@ mod tests { format!("{}", ScalarValue::Date64(Some(-790179464505600000))), "" ); + // These used to panic too, see https://github.com/apache/datafusion/issues/24892 + assert_eq!(format!("{}", ScalarValue::Date64(Some(i64::MIN))), ""); + assert_eq!(format!("{}", ScalarValue::Date64(Some(i64::MAX))), ""); } #[test]