comphead commented on code in PR #13466: URL: https://github.com/apache/datafusion/pull/13466#discussion_r1850732512
########## datafusion/functions/src/datetime/date_part.rs: ########## @@ -261,14 +283,63 @@ fn get_date_part_doc() -> &'static Documentation { }) } -/// Invoke [`date_part`] and cast the result to Float64 -fn date_part_f64(array: &dyn Array, part: DatePart) -> Result<ArrayRef> { - Ok(cast(date_part(array, part)?.as_ref(), &Float64)?) +/// Invoke [`date_part`] on an `array` (e.g. Timestamp) and convert the +/// result to a total number of seconds, milliseconds, microseconds or +/// nanoseconds +fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result<ArrayRef> { + // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond + if unit == Nanosecond { + return internal_err!("unit {unit:?} not supported"); + } + + let conversion_factor = match unit { Review Comment: we should probably factor out the common part for this conversion in future. its too many hardcoded conversions between second fraction and corresponding long value in the project. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org