Skip to content

Guard to_timestamp decimal overflow#22307

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
apache:mainfrom
Sean-Kenneth-Doherty:codex/to-timestamp-decimal-overflow
Open

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

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

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
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

1 participant