Jefffrey commented on code in PR #22610:
URL: https://github.com/apache/datafusion/pull/22610#discussion_r3385951689
##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -420,14 +418,46 @@ fn date_bin_months_interval(stride_months: i64, source:
i64, origin: i64) -> Res
}
fn to_utc_date_time(nanos: i64) -> Result<DateTime<Utc>> {
- let secs = nanos / NANOS_PER_SEC;
- let nsec = (nanos % NANOS_PER_SEC) as u32;
+ // DateTime::from_timestamp requires a non-negative nanosecond part.
+ let secs = nanos.div_euclid(NANOS_PER_SEC);
+ let nsec = nanos.rem_euclid(NANOS_PER_SEC) as u32;
match DateTime::from_timestamp(secs, nsec) {
Some(dt) => Ok(dt),
None => exec_err!("Invalid timestamp value"),
}
}
+fn timestamp_scale<T: ArrowTimestampType>() -> i64 {
+ match T::UNIT {
+ Nanosecond => 1,
+ Microsecond => NANOS_PER_MICRO,
+ Millisecond => NANOS_PER_MILLI,
+ Second => NANOSECONDS,
+ }
+}
+
+// Scale to nanoseconds and report overflow as a normal error.
+fn checked_scale_to_nanos(x: i64, scale: i64) -> Result<i64> {
+ x.checked_mul(scale).ok_or_else(|| {
+ ArrowError::InvalidArgumentError(format!(
Review Comment:
doesnt need to be an arrowerror anymore, can just be datafusion error
--
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]