andygrove commented on code in PR #5081:
URL: https://github.com/apache/datafusion-comet/pull/5081#discussion_r3684661489


##########
native/spark-expr/src/math_funcs/modulo_expr.rs:
##########
@@ -63,6 +77,61 @@ pub fn spark_modulo(args: &[ColumnarValue], fail_on_error: 
bool) -> Result<Colum
     }
 }
 
+/// Computes floating point remainder in ANSI mode using `mod_checked`, which 
raises
+/// `DivideByZero` when the divisor is zero. `-0.0` triggers the error too, 
since
+/// `mod_checked` compares the divisor against zero with IEEE 754 equality — 
matching
+/// Spark, which also treats `-0.0` as a zero divisor.
+fn checked_float_modulo(
+    lhs: &ColumnarValue,
+    rhs: &ColumnarValue,
+    data_type: &DataType,
+) -> Result<ColumnarValue> {
+    let (left, right): (ArrayRef, ArrayRef) = match (lhs, rhs) {
+        (ColumnarValue::Array(l), ColumnarValue::Array(r)) => (Arc::clone(l), 
Arc::clone(r)),
+        (ColumnarValue::Scalar(l), ColumnarValue::Array(r)) => {
+            (l.to_array_of_size(r.len())?, Arc::clone(r))
+        }
+        (ColumnarValue::Array(l), ColumnarValue::Scalar(r)) => {
+            (Arc::clone(l), r.to_array_of_size(l.len())?)
+        }
+        (ColumnarValue::Scalar(l), ColumnarValue::Scalar(r)) => 
(l.to_array()?, r.to_array()?),
+    };
+
+    let result: ArrayRef = match data_type {
+        DataType::Float32 => 
Arc::new(checked_modulo_kernel::<Float32Type>(&left, &right)?),
+        DataType::Float64 => 
Arc::new(checked_modulo_kernel::<Float64Type>(&left, &right)?),
+        _ => return internal_err!("checked_float_modulo called with 
{data_type}"),

Review Comment:
   Applied in 63f174b7.



-- 
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]

Reply via email to