buraksenn opened a new pull request, #24049:
URL: https://github.com/apache/datafusion/pull/24049
## Which issue does this PR close?
- Closes N\A but I can open an issue
## Rationale for this change
Formatted `to_date` inputs are parsed as milliseconds since the Unix epoch
and then converted to `Date32` days. Integer division truncates toward zero, so
negative sub-day timestamps are incorrectly mapped to day `0` instead of day
`-1`.
```sql
-- DataFusion before this change
SELECT to_date('1969-12-31 12:00:00', '%Y-%m-%d %H:%M:%S');
-- 1970-01-01
-- PostgreSQL
SELECT to_date('1969-12-31 12:00:00', 'YYYY-MM-DD HH24:MI:SS');
-- 1969-12-31
-- DuckDB
SELECT CAST(strptime('1969-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') AS DATE);
-- 1969-12-31
```
## What changes are included in this PR?
Use Euclidean division when converting formatted timestamp milliseconds to
days, preserving the correct date for timestamps before the Unix epoch.
## Are these changes tested?
Yes new slt test for this case.
## Are there any user-facing changes?
No API changes. Formatted pre-epoch datetimes now return the correct date.
--
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]