Skip to content

Guard date_trunc lower-bound truncation#22303

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
apache:mainfrom
Sean-Kenneth-Doherty:codex/date-trunc-lower-bound
Open

Guard date_trunc lower-bound truncation#22303
Sean-Kenneth-Doherty wants to merge 1 commit into
apache:mainfrom
Sean-Kenneth-Doherty:codex/date-trunc-lower-bound

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 17, 2026

Which issue does this PR close?

Rationale for this change

Truncating a near-lower-bound nanosecond timestamp to a coarser calendar unit can produce a timestamp outside Arrow's nanosecond range. date_trunc_coarse already used fallible timestamp conversion, but it unwrapped the final conversion back to nanoseconds and could panic.

What changes are included in this PR?

  • Convert the final out-of-range truncation case into a DataFusion execution error.
  • Add a small string helper for user-facing granularity names in the error.
  • Add a unit regression and a sqllogictest regression for lower-bound nanosecond truncation.

Are these changes tested?

Yes:

  • 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 date_trunc_out_of_range_lower_bound_returns_error
  • CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target CARGO_BUILD_JOBS=2 cargo test -p datafusion-sqllogictest --test sqllogictests -- date_trunc_boundaries.slt
  • CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target CARGO_BUILD_JOBS=2 cargo clippy -p datafusion-functions --lib -- -D warnings

Are there any user-facing changes?

Instead of panicking, out-of-range date_trunc results now return an error.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 17, 2026
@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Author

Local validation for the current head (40335934b):

  • cargo fmt --check --all
  • git diff --check origin/main...HEAD && git diff --check
  • cargo test -p datafusion-functions date_trunc_out_of_range_lower_bound_returns_error (1 passed)
  • Ran the locally built sqllogictests driver from datafusion/sqllogictest with the date_trunc_boundaries filter; it completed 1/1 files.

Hosted checks currently only show the labeler, so this covers the focused unit and SQL regression paths for the lower-bound date_trunc case.

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_trunc unwraps out-of-range lower-bound timestamp truncation

1 participant