Skip to content

[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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

pasar6987
Copy link

What changes were proposed in this pull request?

  1. Updated error condition: Changed MOD_BY_ZERO to REMAINDER_BY_ZERO in error-conditions.json with an appropriate error message "Remainder by zero" instead of "Mod by zero"
  2. Updated test cases: Modified ArithmeticExpressionSuite.scala to separate division and remainder operation tests, ensuring that remainder operations (Remainder and Pmod) 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. Use try_mod to tolerate divisor being 0 and return NULL instead." instead of the misleading DIVIDE_BY_ZERO error.

Why are the changes needed?

In ANSI mode, when executing spark.sql("select mod(10,0)"), the system incorrectly throws a DIVIDE_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.

@github-actions github-actions bot added the SQL label Jul 5, 2025
@HyukjinKwon
Copy link
Member

cc @gengliangwang

@pasar6987
Copy link
Author

@gengliangwang Could you please review this pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants