Skip to content

Guard to_timestamp decimal overflow#22307

Merged
Jefffrey merged 1 commit into
apache:mainfrom
Sean-Kenneth-Doherty:codex/to-timestamp-decimal-overflow
May 25, 2026
Merged

Guard to_timestamp decimal overflow#22307
Jefffrey merged 1 commit into
apache:mainfrom
Sean-Kenneth-Doherty:codex/to-timestamp-decimal-overflow

Conversation

@Sean-Kenneth-Doherty

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

to_timestamp converted Decimal128 inputs to nanoseconds with unchecked i128 multiplication followed by an as i64 cast. Large Decimal128 values could overflow during nanosecond scaling, causing a panic in debug builds or a wrapped timestamp value in release builds.

What changes are included in this PR?

  • Convert Decimal128-to-nanoseconds scaling to checked arithmetic.
  • Return a DataFusion error when the scaled value cannot fit in timestamp nanoseconds.
  • Cover both scalar and array Decimal128 overflow paths.
  • Add a sqllogictest regression for the reported query shape.

Are these changes tested?

  • cargo fmt --check
  • git diff --check
  • CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions --lib to_timestamp_decimal128
  • CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target CARGO_BUILD_JOBS=2 cargo clippy -p datafusion-functions --lib -- -D warnings

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 17, 2026

@kosiew kosiew left a comment

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.

@Sean-Kenneth-Doherty
Thanks for the fix

Looks 👍 to me

@Jefffrey Jefffrey added this pull request to the merge queue May 25, 2026
@Jefffrey

Copy link
Copy Markdown
Contributor

Thanks @Sean-Kenneth-Doherty & @kosiew

Merged via the queue into apache:main with commit 7ed3b69 May 25, 2026
55 of 58 checks passed
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: to_timestamp overflows converting large Decimal128 to nanoseconds

3 participants