Skip to content

fix date_trunc overflows converting extreme non-ns timestamps to nanoseconds#22262

Open
xiedeyantu wants to merge 1 commit into
apache:mainfrom
xiedeyantu:date_trunc
Open

fix date_trunc overflows converting extreme non-ns timestamps to nanoseconds#22262
xiedeyantu wants to merge 1 commit into
apache:mainfrom
xiedeyantu:date_trunc

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

date_trunc can panic during planning and constant folding when it receives extreme non-nanosecond timestamps. The overflow happens while converting values to nanoseconds, so a valid SQL query can crash the planner instead of returning a proper error. This change makes that path fail gracefully with a planning error.

What changes are included in this PR?

  • Adds overflow checks to the timestamp scale conversion used by date_trunc.
  • Converts the panic into a normal out-of-range planning error.
  • Adds regression coverage for extreme Timestamp(Second), Timestamp(Millisecond), and Timestamp(Microsecond) inputs.
  • Adds a SQL-level regression test for the arrow_cast(...) plus date_trunc(...) repro.

Are these changes tested?

  • Yes. I added regression tests and verified the repro now returns an error instead of panicking.

Are there any user-facing changes?

  • Yes. Out-of-range timestamp inputs now produce a planning error rather than aborting the query with a panic.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 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: date_trunc overflows converting extreme non-ns timestamps to nanoseconds

2 participants