Skip to content

fix: avoid panic in date_bin compute_distance near i64::MIN#22408

Open
SAY-5 wants to merge 1 commit into
apache:mainfrom
SAY-5:say-fix-date-bin-compute-distance-overflow
Open

fix: avoid panic in date_bin compute_distance near i64::MIN#22408
SAY-5 wants to merge 1 commit into
apache:mainfrom
SAY-5:say-fix-date-bin-compute-distance-overflow

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 21, 2026

Which issue does this PR close?

Rationale for this change

date_bin panics with attempt to subtract with overflow when the source timestamp sits near i64::MIN because compute_distance does time_diff - (time_diff % stride) and then time_delta - stride on raw i64. The scalar pipeline already maps Err from bin_fn into NULL, so the fix is to surface the overflow as a normal error.

What changes are included in this PR?

  • Convert compute_distance to return Result<i64> and use checked_sub.
  • Propagate the result through date_bin_nanos_interval and date_bin_months_interval, plus replace the trailing origin + time_delta with checked_add.

Are these changes tested?

Yes. Added test_date_bin_compute_distance_i64_min which previously panicked and now returns NULL. Ran cargo test -p datafusion-functions --lib -- datetime::date_bin, cargo fmt --check, and cargo clippy -p datafusion-functions --lib --tests --no-deps.

Are there any user-facing changes?

Queries that previously panicked on extreme timestamps now return NULL (consistent with the existing out-of-range behavior covered by test_date_bin_out_of_range).

@github-actions github-actions Bot added the functions Changes to functions implementation label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: date_bin compute_distance subtracts past i64::MIN

1 participant