[SPARK-52659][SQL]Misleading modulo error message in ansi mode #51378
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
MOD_BY_ZERO
toREMAINDER_BY_ZERO
inerror-conditions.json
with an appropriate error message "Remainder by zero" instead of "Mod by zero"ArithmeticExpressionSuite.scala
to separate division and remainder operation tests, ensuring that remainder operations (Remainder
andPmod
) expect "Remainder by zero" error message instead of "Division by zero"The mod function now correctly throws
REMAINDER_BY_ZERO
error with message "Remainder by zero. Usetry_mod
to tolerate divisor being 0 and return NULL instead." instead of the misleadingDIVIDE_BY_ZERO
error.Why are the changes needed?
In ANSI mode, when executing
spark.sql("select mod(10,0)")
, the system incorrectly throws aDIVIDE_BY_ZERO
error with message "Division by zero".Does this PR introduce any user-facing change?
Yes. This PR changes the user-facing error message for modulo operations in ANSI mode.
Before:
org.apache.spark.SparkArithmeticException: [DIVIDE_BY_ZERO] Division by zero. Use try_divide to tolerate divisor being 0 and return NULL instead.
After:
org.apache.spark.SparkArithmeticException: [REMAINDER_BY_ZERO] Remainder by zero. Use try_mod to tolerate divisor being 0 and return NULL instead.
How was this patch tested?
Updated existing unit tests.
Was this patch authored or co-authored using generative AI tooling?
No.
This is my first pull request. I'm writing this pull request after reviewing the documentation as much as possible, but if there's anything wrong, please let me know.