Marouane-elfadli opened a new pull request, #27214:
URL: https://github.com/apache/datafusion/pull/27214
## Which issue does this PR close?
- Closes #27212.
## Rationale for this change
`extract(epoch from <interval>)` returns the wrong number of seconds once an
interval reaches one year. DataFusion counts 12 months as 360 days.
PostgreSQL and DuckDB count each whole year as 365.25 days and only use 30
days for the leftover months, so `interval '1 year'` was 5.25 days short.
Intervals under a year give the same answer in all three.
## What changes are included in this PR?
Added `months_to_seconds()` in `date_part.rs`. It counts whole years as
365.25 days and leftover months as 30 days. The `Interval(YearMonth)` and
`Interval(MonthDayNano)` branches of `epoch()` now use it. Intervals under a
year are unchanged.
Before / after:
1 year 31104000 -> 31557600
14 months 36288000 -> 36741600
## What is the testing strategy for this PR?
- A unit test, `test_months_to_seconds`, in `date_part.rs`.
- `sqllogictest` cases in `datetime/date_part.slt` for the five rows from the
issue and for `Interval(YearMonth)`. The expected values are what
PostgreSQL 18 returns.
## Are there any user-facing changes?
Yes, only for intervals of a year or more: `extract(epoch from ...)` now
returns the PostgreSQL/DuckDB value instead of the 360-day one. No public API
changes.
--
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]