Skip to content

Commit 38c4c6a

Browse files
committed
chore: address date_bin error feedback
1 parent e3472ae commit 38c4c6a

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎datafusion/functions/src/datetime/date_bin.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn date_bin_months_interval(stride_months: i64, source: i64, origin: i64) -> Res
418418
}
419419

420420
fn to_utc_date_time(nanos: i64) -> Result<DateTime<Utc>> {
421-
// DateTime::from_timestamp requires a non-negative nanosecond part.
421+
// Keep negative sub-second values normalized as seconds + non-negative nanos.
422422
let secs = nanos.div_euclid(NANOS_PER_SEC);
423423
let nsec = nanos.rem_euclid(NANOS_PER_SEC) as u32;
424424
match DateTime::from_timestamp(secs, nsec) {
@@ -438,12 +438,10 @@ fn timestamp_scale<T: ArrowTimestampType>() -> i64 {
438438

439439
// Scale to nanoseconds and report overflow as a normal error.
440440
fn checked_scale_to_nanos(x: i64, scale: i64) -> Result<i64> {
441-
x.checked_mul(scale).ok_or_else(|| {
442-
ArrowError::InvalidArgumentError(format!(
443-
"date_bin timestamp value {x} * scale {scale} overflows i64"
444-
))
445-
.into()
446-
})
441+
match x.checked_mul(scale) {
442+
Some(scaled) => Ok(scaled),
443+
None => exec_err!("date_bin timestamp value {x} * scale {scale} overflows i64"),
444+
}
447445
}
448446

449447
fn validate_time_stride(stride: &Interval) -> Result<()> {

0 commit comments

Comments
 (0)