rtaylor-cf opened a new issue, #28016:
URL: https://github.com/apache/datafusion/issues/28016
### Describe the bug
Since #19078 (first released in 52.0.0), `to_timestamp`,
`to_timestamp_seconds`, `to_timestamp_millis`, `to_timestamp_micros` and
`to_timestamp_nanos` return `Timestamp(unit, <execution time_zone>)` for every
input, including inputs that already carry a timezone. Combined with the
default `datafusion.execution.time_zone` of `None` (#18359), a timezone-aware
input loses its timezone.
As a result, casting the result to a string no longer includes the offset
(`1970-01-01T00:00:00Z` in 51.0.0 becomes `1970-01-01T00:00:00` in 52.0.0).
#11037 / #11038 previously made these functions preserve the input timezone.
#19078 describes changes to how *naive* inputs are interpreted, but it also
changes the result for timezone-aware inputs, and I couldn't find discussion of
that in the PR.
### To Reproduce
In `datafusion-cli` with the default config:
```sql
SELECT arrow_typeof(to_timestamp(arrow_cast(0, 'Timestamp(Nanosecond,
Some("UTC"))')));
SELECT CAST(to_timestamp(arrow_cast(0, 'Timestamp(Nanosecond,
Some("UTC"))')) AS VARCHAR);
```
datafusion-cli 51.0.0:
```
Timestamp(ns, "UTC")
1970-01-01T00:00:00Z
```
datafusion-cli 52.0.0:
```
Timestamp(ns)
1970-01-01T00:00:00
```
The precision variants behave the same way:
```sql
SELECT arrow_typeof(to_timestamp_seconds(t)) s,
arrow_typeof(to_timestamp_millis(t)) ms,
arrow_typeof(to_timestamp_micros(t)) us,
arrow_typeof(to_timestamp_nanos(t)) ns
FROM (SELECT arrow_cast(0, 'Timestamp(Nanosecond, Some("UTC"))') t);
```
- 51.0.0: `Timestamp(s, "UTC")`, `Timestamp(ms, "UTC")`, `Timestamp(µs,
"UTC")`, `Timestamp(ns, "UTC")`
- 52.0.0: `Timestamp(s)`, `Timestamp(ms)`, `Timestamp(µs)`, `Timestamp(ns)`
### Expected behavior
A timezone-aware input keeps its timezone when
`datafusion.execution.time_zone` is `None`, as it did after #11038. When an
execution time zone is set, converting to it seems reasonable, but a `None`
execution time zone shouldn't strip an existing zone. Naive inputs would keep
the #19078 behaviour.
### Additional context
Current code on main: `ToTimestampFunc::return_type` returns
`Timestamp(Nanosecond, self.timezone)` regardless of argument types, and
`invoke_with_args` casts `Timestamp(_, _)` inputs to that type
(datafusion/functions/src/datetime/to_timestamp.rs).
A possible fix is to derive the return type from the arguments
(`return_field_from_args`): keep the input's timezone when the input is
timezone-aware and the execution time zone is `None`.
Related: #17998, #19078, #18359, #24632 / #24636 (a follow-up fix for string
inputs).
### Willingness to contribute
I plan to contribute a fix for this bug independently
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]