Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion datafusion/functions/src/datetime/date_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ impl Interval {

// return time in nanoseconds that the source timestamp falls into based on the stride and origin
fn date_bin_nanos_interval(stride_nanos: i64, source: i64, origin: i64) -> Result<i64> {
let time_diff = source - origin;
let time_diff = source.checked_sub(origin).ok_or_else(|| {
arrow::error::ArrowError::InvalidArgumentError(format!(
"date_bin source timestamp {source} - origin {origin} overflows i64"
))
})?;

// distance from origin to bin
let time_delta = compute_distance(time_diff, stride_nanos);
Expand Down
10 changes: 10 additions & 0 deletions datafusion/sqllogictest/test_files/date_bin_errors.slt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ select date_bin(
timestamp '1984-01-07 00:00:00'
) as b;
----
NULL

# Extreme timestamp overflow: source - origin overflows i64 (should return NULL, not panic)
query P
select date_bin(
interval '1 nanosecond',
arrow_cast(9223372036854775807, 'Timestamp(Nanosecond, None)'),
arrow_cast(-9223372036854775808, 'Timestamp(Nanosecond, None)')
);
----
NULL
Loading