mbutrovich commented on code in PR #342:
URL: https://github.com/apache/datafusion-spark/pull/342#discussion_r4602774141


##########
crates/sqllogictest/test_files/math/pmod.slt:
##########
@@ -389,6 +389,88 @@ SELECT pmod(arrow_cast(-10, 'Int64'), arrow_cast(3, 
'Int64')) as pmod_int64_2;
 ----
 2
 
+# PMOD tests at the signed integer boundaries.
+# Spark evaluates `(r + n) % n` with Java arithmetic: `byte` and `short` are
+# promoted to `int` and never overflow, while `int` and `long` wrap around.

Review Comment:
   Could we run these boundary cases with `enable_ansi_mode = true` as well? 
Spark's `Pmod` keeps wrapping under ANSI mode. Its generated code uses plain 
`+` and `%` for every integer width ([arithmetic.scala 
L1137-L1155](https://github.com/apache/spark/blob/32f7299601108917fb01920a54e084595b7b3bf8/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala#L1137-L1155)),
 not `Math.addExact` the way `Add` does under ANSI. PySpark 4.2.0 with 
`spark.sql.ansi.enabled=true` returns the same values as with it off, for 
example `pmod(-1, -2147483648)` is `2147483647` and `pmod(-1Y, -128Y)` is `-1`. 
The change uses `add_wrapping` in both modes, which is right, but no test 
checks that ANSI mode keeps wrapping.



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