sdf-jkl opened a new issue, #22033:
URL: https://github.com/apache/datafusion/issues/22033
### Is your feature request related to a problem or challenge?
Working on #18319 I noticed that `date_trunc` defines its own
`DateTruncGranularity` enum.
https://github.com/apache/datafusion/blob/2c7af17529533cd2458b6b227a9128294e1fc209/datafusion/functions/src/datetime/date_trunc.rs#L56-L67
`date_part` solves the same parsing problem differently — it delegates to
`arrow_cast::parse::IntervalUnit::from_str`:
https://github.com/apache/datafusion/blob/2c7af17529533cd2458b6b227a9128294e1fc209/datafusion/functions/src/datetime/date_part.rs#L230-L244
This leads to a user-visible inconsistency between the two functions. For
example, `date_part` accepts "mon" | "mons" | "month" | "months", while
`date_trunc` only accepts "month".
`IntervalUnit`, however, is the wrong enum for either of these functions —
it exists to parse Postgres INTERVAL literals (INTERVAL '1 year 2 months'),
which is why it has `Century` / `Decade` but no `Quarter` (Postgres rejects
INTERVAL '1 QUARTER'). The right counterpart is
`arrow_arith::temporal::DatePart`, which represents the date-part field
namespace, includes `Quarter`, and is #[non_exhaustive]:
https://github.com/apache/arrow-rs/blob/8091f3f17b2de355f7c47e7a0907000d308f8f3e/arrow-arith/src/temporal.rs#L38-L79
### Describe the solution you'd like
I propose:
- Add a `FromStr` impl for `arrow_arith::DatePart` (with the Postgres alias
map currently inside IntervalUnit::from_str plus the date-part-only field
names).
- Migrate `date_part`, `date_trunc`, and the Spark variants (`date_trunc`,
`trunc`, `time_trunc`, `date_part`) to the new parser. The unparser sites in
sql/src/unparser/utils.rs can also use it as an input canonicalizer.
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
--
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]