xangelix opened a new issue, #27952:
URL: https://github.com/apache/datafusion/issues/27952
### Describe the bug
`date_trunc` converts second, millisecond and microsecond timestamps to
nanoseconds before truncating them to a week, month, quarter or year, or to an
hour or a day when the timestamp has a timezone. Valid timestamps outside the
nanosecond range (before 1677-09-21 or after 2262-04-11) then fail the whole
query with `Execution error: Timestamp … out of range`, although their own type
holds them.
Such values are common in real data: 1601-01-01 is the Windows FILETIME
epoch (a zero FILETIME), and 9999-12-31 is a common "no end" sentinel.
### To Reproduce
```sql
-- 1601-03-15T13:45:30.123456Z
SELECT date_trunc('day', arrow_cast(-11638116869876544, 'Timestamp(µs,
"UTC")'));
-- Execution error: Timestamp -11638116869876544 out of range
SELECT date_trunc('month', arrow_cast(-11638116869876544, 'Timestamp(µs)'));
-- Execution error: Timestamp -11638116869876544 out of range
```
### Expected behavior
`date_trunc('hour'|'day', …)` on a timezone-less column works (it truncates
in the input's unit), so the result depends on whether the column has a
timezone.
### Additional context
`general_date_trunc` multiplies the value into nanoseconds before calling
`date_trunc_coarse`.
### 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]