xangelix opened a new issue, #27955: URL: https://github.com/apache/datafusion/issues/27955
### Describe the bug For a timezone-aware timestamp in seconds, milliseconds or microseconds, `date_bin` and `to_char` cast their argument to nanoseconds, though both declare a signature for each unit: - `date_bin` returns a nanosecond timestamp for a microsecond input with a timezone (a microsecond input without a timezone stays in microseconds); - both fail on values outside the nanosecond range (before 1677-09-21 or after 2262-04-11). ### To Reproduce ```sql SELECT arrow_typeof(date_bin(INTERVAL '1 hour', arrow_cast(1, 'Timestamp(µs, "UTC")'))); -- Timestamp(ns, "UTC"); expected Timestamp(µs, "UTC") SELECT to_char(arrow_cast(-11644473600000000, 'Timestamp(µs, "UTC")'), '%Y-%m-%d'); -- Cannot cast Timestamp(µs, "UTC") value -11644473600000000 to Timestamp(ns): converted value -- exceeds the representable i64 range; expected 1601-01-01 SELECT to_char(arrow_cast(-11644473600000000, 'Timestamp(µs)'), '%Y-%m-%d'); -- 1601-01-01 (works without a timezone) ``` ### Expected behavior The argument keeps its unit, as it does without a timezone. ### Additional context The signatures use `Timestamp(unit, Some(TIMEZONE_WILDCARD))`. `fields_with_udf` (and the deprecated `data_types`) check whether the arguments already match a signature with `==`, which never holds for the wildcard, so coercion takes the first listed signature the argument can be cast to. ### 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]
