Skip to content

Support casting Date32/Date64 to time zone aware Timestamps. #7140

@friendlymatthew

Description

@friendlymatthew

The Date data types can cast to a Timestamp, as long as no time zone is specified. But you can't cast into a timezone aware timestamp.

For example:

> select to_char(arrow_cast('2023-09-04'::date, 'Timestamp(Second, None)'), '%Y-%m-%dT%H:%M:%S%.3f');

+-------------------------------------------------------------------------------------------------------+
| to_char(arrow_cast(Utf8("2023-09-04"),Utf8("Timestamp(Second, None)")),Utf8("%Y-%m-%dT%H:%M:%S%.3f")) |
+-------------------------------------------------------------------------------------------------------+
| 2023-09-04T00:00:00.000                                                                               |
+-------------------------------------------------------------------------------------------------------+
1 row(s) fetched.

> select to_char(arrow_cast('2023-09-04'::date, 'Timestamp(Second, Some("UTC"))'), '%Y-%m-%dT%H:%M:%S%.3f');
# doesn't work!

Describe the solution you'd like
Update the casting rules in arrow-cast such that Date32 and Date64 can cast into a timezone aware timestamp.

Additional context
Motivated by apache/datafusion#14638

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions