Skip to content

panic: date_trunc unwraps out-of-range lower-bound timestamp truncation #22214

@Dandandan

Description

@Dandandan

Describe the bug

date_trunc can panic during planning/constant folding for lower-bound nanosecond timestamps. Truncating to a coarser unit can produce a value outside Arrow's nanosecond timestamp range, and the code unwraps None.

To Reproduce

EXPLAIN SELECT date_trunc('year', TIMESTAMP '1677-09-22 00:00:00');

Actual behavior

thread 'main' panicked at datafusion/functions/src/datetime/date_trunc.rs:649:14:
called `Option::unwrap()` on a `None` value

Expected behavior

Return an error or NULL for an out-of-range truncated timestamp; do not panic.

Notes

Other coarse granularities near the lower nanosecond timestamp bound hit the same unwrap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions