Skip to content

date_trunc panicked with message: called Option::unwrap() on a None value #8899

@appletreeisyellow

Description

@appletreeisyellow

Describe the bug

date_trunc() panicked for some timestamps that are casted to a timezone other than UTC

For example, this query causes a panic:

SELECT date_trunc('week', arrow_cast(arrow_cast('2023-10-29T00:00:00Z', 'Timestamp(Nanosecond, Some("UTC"))'), 'Timestamp(Nanosecond, Some("Europe/Berlin"))'));

Even though a different timestamp works fine, e.g. 2023-10-29T02:00:00Z

To Reproduce

Run the above query in DataFusion CLI v34.0.0

2023-10-29T00:00:00Z panicked

$ datafusion-cli

DataFusion CLI v34.0.0SELECT date_trunc('week', arrow_cast(arrow_cast('2023-10-29T00:00:00Z', 'Timestamp(Nanosecond, Some("UTC"))'), 'Timestamp(Nanosecond, Some("Europe/Berlin"))'));
thread 'main' panicked at /private/tmp/datafusion-20231217-5103-4z8blm/arrow-datafusion-34.0.0/datafusion/physical-expr/src/datetime_expressions.rs:335:14:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

2023-10-29T02:00:00Z works

$ datafusion-cli

DataFusion CLI v34.0.0SELECT date_trunc('week', arrow_cast(arrow_cast('2023-10-29T02:00:00Z', 'Timestamp(Nanosecond, Some("UTC"))'), 'Timestamp(Nanosecond, Some("Europe/Berlin"))'));
+-------------------------------------------------------+
| date_trunc(Utf8("week"),Utf8("2023-10-29T02:00:00Z")) |
+-------------------------------------------------------+
| 2023-10-23T00:00:00+02:00                             |
+-------------------------------------------------------+
1 row in set. Query took 0.005 seconds.

Expected behavior

Handle the result correctly or return an error instead of panicking

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions