Skip to content

fix date_bin overflows scaling extreme Timestamp(Second) source#22315

Open
xiedeyantu wants to merge 11 commits into
apache:mainfrom
xiedeyantu:db
Open

fix date_bin overflows scaling extreme Timestamp(Second) source#22315
xiedeyantu wants to merge 11 commits into
apache:mainfrom
xiedeyantu:db

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

date_bin could panic during planning or constant evaluation when scaling a non-nanosecond source timestamp to nanoseconds overflowed. This change makes that path return a regular error instead of panicking.

What changes are included in this PR?

  • Added checked overflow handling for source timestamp scaling in date_bin.
  • Return an error for out-of-range source timestamp conversion instead of panicking.
  • Preserved existing NULL behavior for unrelated out-of-range date_bin cases.
  • Added Rust unit test and sqllogictest coverage for the overflow case.

Are these changes tested?

Yes.

Verified with:

  • cargo test -p datafusion-functions test_date_bin --lib
  • cargo test -p datafusion-sqllogictest --test sqllogictests date_bin_errors

Are there any user-facing changes?

Yes. Queries that previously could panic now return a normal error:

Execution error: DATE_BIN source timestamp ... cannot be represented in nanoseconds

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 17, 2026
Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
@xiedeyantu
Copy link
Copy Markdown
Member Author

@nathanb9 Thanks for your review. All comments have been revised according to your suggestions. Please confirm if this is what you expected.

Copy link
Copy Markdown
Contributor

@nathanb9 nathanb9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is better way to handle it too @xiedeyantu Thanks for fixing quickly.

FYI im not a committer so youll need someone else as well.

@xiedeyantu
Copy link
Copy Markdown
Member Author

I think this is better way to handle it too @xiedeyantu Thanks for fixing quickly.

FYI im not a committer so youll need someone else as well.

Thanks all the same.

@xiedeyantu
Copy link
Copy Markdown
Member Author

@Dandandan Could you help me take a look?

Comment thread datafusion/functions/src/datetime/date_bin.rs
Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
@xiedeyantu
Copy link
Copy Markdown
Member Author

@Jefffrey I tried to fix it, but I'm not sure if it's what you want. Could you take a look?

@xiedeyantu xiedeyantu requested a review from Jefffrey May 27, 2026 13:56
)
})?;
Ok(stride_fn(stride, scaled, origin)
.ok()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
Comment thread datafusion/functions/src/datetime/date_bin.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: date_bin overflows scaling extreme Timestamp(Second) source

3 participants