Skip to content

date_trunc(null) results in a panic #6701

Closed
@alamb

Description

@alamb

Describe the bug

Calling the date_trunc(null) function results in a panic

To Reproduce

DataFusion CLI v26.0.0
❯ select date_trunc('2021-02-01T12:01:02', 'hour');
Optimizer rule 'simplify_expressions' failed
caused by
Arrow error: Parser error: Error parsing timestamp from 'hour': timestamp must contain at least 10 characters
❯ select date_trunc('hour', '2021-02-01T12:01:02');
+------------------------------------------------------+
| date_trunc(Utf8("hour"),Utf8("2021-02-01T12:01:02")) |
+------------------------------------------------------+
| 2021-02-01T12:00:00                                  |
+------------------------------------------------------+
1 row in set. Query took 0.074 seconds.
❯ select date_trunc('hour', null);
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/datetime_expressions.rs:314:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

null should be returned

Additional context

Found while reviewing #6654 from @Weijun-H

The issue is the use of unwrap() in the date_trunc implementation

I think this is a good first issue for someone as it is localized (involves removing unwrap()) and writing some tests using .slt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions