coderfender commented on code in PR #21212:
URL: https://github.com/apache/datafusion/pull/21212#discussion_r3008445960
##########
datafusion/spark/src/function/conversion/cast.rs:
##########
@@ -34,12 +35,36 @@ use std::sync::Arc;
const MICROS_PER_SECOND: i64 = 1_000_000;
-/// Convert seconds to microseconds with saturating overflow behavior (matches
spark spec)
+/// Convert integer seconds to microseconds with saturating overflow behavior
#[inline]
fn secs_to_micros(secs: i64) -> i64 {
secs.saturating_mul(MICROS_PER_SECOND)
}
+/// Convert float seconds to microseconds
+/// Returns None for NaN/Infinity/Overflow in non-ANSI mode, error in ANSI mode
+#[inline]
+fn float_secs_to_micros(val: f64, enable_ansi_mode: bool) ->
Result<Option<i64>> {
+ if val.is_nan() || val.is_infinite() {
+ if enable_ansi_mode {
+ return exec_err!(
+ "Cannot cast {} to TIMESTAMP",
+ if val.is_nan() { "NaN" } else { "Infinity" }
+ );
+ }
+ return Ok(None);
+ }
+ let micros = val * MICROS_PER_SECOND as f64;
+ if micros >= i64::MIN as f64 && micros <= i64::MAX as f64 {
+ Ok(Some(micros as i64))
+ } else {
+ if enable_ansi_mode {
+ return exec_err!("Overflow casting {} to TIMESTAMP", val);
+ }
+ Ok(None)
Review Comment:
great catch ! I fixed it to return `i64::Max / i64::Min`
--
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]