-
Notifications
You must be signed in to change notification settings - Fork 28.8k
[SPARK-52659][SQL]Misleading modulo error message in ansi mode #51378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
pasar6987
wants to merge
14
commits into
apache:master
from
pasar6987:Misleading-modulo-error-message-in-ANSI-mode
Closed
[SPARK-52659][SQL]Misleading modulo error message in ansi mode #51378
pasar6987
wants to merge
14
commits into
apache:master
from
pasar6987:Misleading-modulo-error-message-in-ANSI-mode
+107
−23
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…//github.com/pasar6987/spark into Misleading-modulo-error-message-in-ANSI-mode
@gengliangwang Could you please review this pull request? |
gengliangwang
approved these changes
Sep 3, 2025
LGTM. Sorry for the late review |
@gengliangwang Thank you for reviewing. There is a correction in the code, so could you please review it again? The test passed. |
gengliangwang
approved these changes
Sep 17, 2025
Thanks, merging to master! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.