Smallfu666 opened a new issue, #6015: URL: https://github.com/apache/datafusion-comet/issues/6015
## Describe the bug In legacy (non-ANSI) mode, negating the minimum of a signed integer type gives two different answers in Comet depending on whether the input arrives as an array or as a scalar. The array path wraps, which matches Spark. The scalar path raises an error. ## Steps to reproduce Negating `Int32(-2147483648)` with `fail_on_error = false`: - array input: returns `-2147483648`, wrapped onto itself - scalar input: returns an arithmetic overflow error ## Root cause `NegativeExpr::evaluate` applies its overflow checks only when `fail_on_error` is set. In legacy mode the scalar arm therefore falls straight through to `ScalarValue::arithmetic_negate`, and that helper uses checked negation for the signed integer scalar variants, regardless of mode: ```rust ScalarValue::Int32(Some(v)) => Ok(ScalarValue::Int32(Some(v.neg_checked()?))), ``` The array arm in the same mode calls `neg_wrapping`, which wraps for the eight integer types. ## Expected behavior Both paths should wrap in legacy mode, matching Spark. Verified against Spark 4.1.3: `UnaryMinus` routes `ByteType | ShortType | IntegerType | LongType` through `MathUtils.negateExact` only when `failOnError` is set, and otherwise negates through the plain numeric, which wraps. ## Additional context Found while reviewing #5982, which changes `NegativeExpr::get_properties` and does not touch either evaluation path. This is pre-existing and was deliberately left out of that PR. #5982 adds `test_legacy_scalar_negation_of_min_errors_unlike_the_array_path`, which pins both halves of the divergence so the current behavior is documented rather than rediscovered. That test will need updating when this is fixed. -- 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]
