andygrove opened a new issue, #5067: URL: https://github.com/apache/datafusion-comet/issues/5067
### Describe the bug Under ANSI mode, `Remainder` on Float/Double operands returns `NaN` for a zero divisor instead of throwing. Spark 4.1 throws `REMAINDER_BY_ZERO` (`DIVIDE_BY_ZERO` on earlier versions) for all numeric types including floating point. Comet's native implementation (`native/spark-expr/src/math_funcs/modulo_expr.rs`) relies on Arrow's `rem` kernel to signal the error: it catches `ArrowError::DivideByZero` and re-raises `remainder_by_zero_error()`. But arrow-arith only produces `DivideByZero` for integer and decimal types. For floats, `Op::Rem` uses `mod_wrapping`, which returns `NaN` for `x % 0.0` and never errors, so the error branch is unreachable for Float32/Float64. The non-ANSI path is correct: `null_if_zero_primitive` nulls zero divisors for floats before the kernel runs. Integral and decimal ANSI remainder are also correct. ### Steps to reproduce ```sql SET spark.sql.ansi.enabled=true; SELECT CAST(1.0 AS DOUBLE) % CAST(0.0 AS DOUBLE); ``` Spark: throws `SparkArithmeticException` with error class `REMAINDER_BY_ZERO`. Comet: returns `NaN`. ### Expected behavior Under ANSI mode, Comet should detect zero divisors for Float32/Float64 explicitly (the Arrow kernel will not do it) and raise the remainder-by-zero error. ### Additional context Found by an ANSI-mode audit of all native expressions against Spark 4.1.1. Related: #2855 tracks using the `Remainder by zero` wording (vs `Divide by zero`) for Spark 4.1+; this issue is about the float path raising no error at all. -- 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]
