You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/05/17 04:37:02 UTC
(datafusion) branch gh-readonly-queue/main/pr-22251-7e90f525c5a0ba3dfd1e215addd0b2a1330fca9b created (now 1a61a599ba)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-22251-7e90f525c5a0ba3dfd1e215addd0b2a1330fca9b
in repository https://gitbox.apache.org/repos/asf/datafusion.git
at 1a61a599ba fix date_bin overflows subtracting extreme nanosecond timestamp origin (#22251)
This branch includes the following new commits:
new 1a61a599ba fix date_bin overflows subtracting extreme nanosecond timestamp origin (#22251)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion) 01/01: fix date_bin overflows subtracting extreme nanosecond timestamp origin (#22251)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-22251-7e90f525c5a0ba3dfd1e215addd0b2a1330fca9b
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 1a61a599baa31fa7e9741c0da519c82f31cc435b
Author: Zhen Chen <cz...@163.com>
AuthorDate: Sun May 17 12:36:42 2026 +0800
fix date_bin overflows subtracting extreme nanosecond timestamp origin (#22251)
## Which issue does this PR close?
- Closes #22210
## Rationale for this change
`date_bin` could overflow when subtracting extreme nanosecond
timestamps, which could trigger a panic. This fix makes that path return
an error instead, so the query safely returns `NULL` rather than
crashing.
## What changes are included in this PR?
- In date_bin.rs, the nanosecond path now uses `checked_sub` instead of
direct subtraction, and returns an `ArrowError::InvalidArgumentError` on
overflow.
- In date_bin_errors.slt, a regression test was added for an extreme
nanosecond timestamp case to verify that overflow returns `NULL` instead
of panicking.
## Are these changes tested?
- Yes. The new sqllogictest covers the regression scenario and verifies
that extreme nanosecond timestamp input returns `NULL`.
## Are there any user-facing changes?
- Yes. `date_bin` is now more robust for extreme nanosecond timestamp
inputs and will return `NULL` instead of panicking.
---
datafusion/functions/src/datetime/date_bin.rs | 6 +++++-
datafusion/sqllogictest/test_files/date_bin_errors.slt | 10 ++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/datafusion/functions/src/datetime/date_bin.rs b/datafusion/functions/src/datetime/date_bin.rs
index 123375cc26..c26623c46b 100644
--- a/datafusion/functions/src/datetime/date_bin.rs
+++ b/datafusion/functions/src/datetime/date_bin.rs
@@ -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);
diff --git a/datafusion/sqllogictest/test_files/date_bin_errors.slt b/datafusion/sqllogictest/test_files/date_bin_errors.slt
index b6cda471d7..b59201eb90 100644
--- a/datafusion/sqllogictest/test_files/date_bin_errors.slt
+++ b/datafusion/sqllogictest/test_files/date_bin_errors.slt
@@ -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
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org