samuelcolvin commented on code in PR #12222:
URL: https://github.com/apache/datafusion/pull/12222#discussion_r1766593376
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -161,22 +163,32 @@ impl ScalarUDFImpl for DatePartFunc {
return exec_err!("Date part '{part}' not supported");
}
- let arr = match part_trim.to_lowercase().as_str() {
- "year" => date_part_f64(array.as_ref(), DatePart::Year)?,
- "quarter" => date_part_f64(array.as_ref(), DatePart::Quarter)?,
- "month" => date_part_f64(array.as_ref(), DatePart::Month)?,
- "week" => date_part_f64(array.as_ref(), DatePart::Week)?,
- "day" => date_part_f64(array.as_ref(), DatePart::Day)?,
- "doy" => date_part_f64(array.as_ref(), DatePart::DayOfYear)?,
- "dow" => date_part_f64(array.as_ref(),
DatePart::DayOfWeekSunday0)?,
- "hour" => date_part_f64(array.as_ref(), DatePart::Hour)?,
- "minute" => date_part_f64(array.as_ref(), DatePart::Minute)?,
- "second" => seconds(array.as_ref(), Second)?,
- "millisecond" => seconds(array.as_ref(), Millisecond)?,
- "microsecond" => seconds(array.as_ref(), Microsecond)?,
- "nanosecond" => seconds(array.as_ref(), Nanosecond)?,
- "epoch" => epoch(array.as_ref())?,
- _ => return exec_err!("Date part '{part}' not supported"),
+ // using IntervalUnit here means we hand off all the work of
supporting plurals (like "seconds")
+ // and synonyms ( like "ms,msec,msecond,millisecond") to Arrow
+ let arr = if let Ok(interval_unit) = IntervalUnit::from_str(part_trim)
{
+ match interval_unit {
+ IntervalUnit::Year => date_part_f64(array.as_ref(),
DatePart::Year)?,
+ IntervalUnit::Month => date_part_f64(array.as_ref(),
DatePart::Month)?,
+ IntervalUnit::Week => date_part_f64(array.as_ref(),
DatePart::Week)?,
+ IntervalUnit::Day => date_part_f64(array.as_ref(),
DatePart::Day)?,
+ IntervalUnit::Hour => date_part_f64(array.as_ref(),
DatePart::Hour)?,
+ IntervalUnit::Minute => date_part_f64(array.as_ref(),
DatePart::Minute)?,
+ IntervalUnit::Second => seconds(array.as_ref(), Second)?,
+ IntervalUnit::Millisecond => seconds(array.as_ref(),
Millisecond)?,
+ IntervalUnit::Microsecond => seconds(array.as_ref(),
Microsecond)?,
+ IntervalUnit::Nanosecond => seconds(array.as_ref(),
Nanosecond)?,
+ // century and decade are not supported by `DatePart`,
although they are supported in postgres
+ _ => return exec_err!("Date part '{part}' not supported"),
+ }
+ } else {
+ // special cases that can be extracted (in postgres) but are not
interval units
+ match part_trim.to_lowercase().as_str() {
+ "qtr" | "quarter" => date_part_f64(array.as_ref(),
DatePart::Quarter)?,
+ "doy" => date_part_f64(array.as_ref(), DatePart::DayOfYear)?,
+ "dow" => date_part_f64(array.as_ref(),
DatePart::DayOfWeekSunday0)?,
+ "epoch" => epoch(array.as_ref())?,
Review Comment:
this should mean epoch is now supported.
--
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]