Skip to content

Conversation

pasar6987
Copy link
Contributor

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

@gengliangwang Could you please review this pull request?

@gengliangwang
Copy link
Member

LGTM. Sorry for the late review
@pasar6987 could you trigger the CI and see if all test passed?

@pasar6987 pasar6987 changed the title [SPARK-52659][SQL]Misleading modulo error message in ansi mode [SPARK-52659][SQL]Misleading modulo error message in ansi mode. Sep 3, 2025
@pasar6987 pasar6987 changed the title [SPARK-52659][SQL]Misleading modulo error message in ansi mode. [SPARK-52659][SQL]Misleading modulo error message in ansi mode Sep 3, 2025
@pasar6987
Copy link
Contributor Author

@gengliangwang Thank you for reviewing. There is a correction in the code, so could you please review it again? The test passed.

@gengliangwang
Copy link
Member

Thanks, merging to master!

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.

4 participants