Repository navigation
[AURON #2746] Fix native decimal remainder returning NULL when an operand exceeds the result type - #2748
Open
zoddtheimmortal wants to merge 1 commit into
Open
[AURON #2746] Fix native decimal remainder returning NULL when an operand exceeds the result type#2748zoddtheimmortal wants to merge 1 commit into
zoddtheimmortal wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The decimal remainder conversion can overflow during scale alignment and raise an execution error even with ANSI disabled, requiring a Spark fallback for unsafe precisions and a boundary regression test.
1 open issue
What changed in this PR
Addresses #2746 by preserving decimal operand types during Auron’s native remainder conversion, avoiding incorrect NULL results when Spark’s result type is narrower than an operand.
Changes:
- Removes operand casts for non-literal divisors while preserving zero-divisor handling.
- Adds Spark compatibility tests covering oversized operands, mixed scales, negative values, zeros, and nulls.
| File | Description |
|---|---|
spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala |
Passes original operand types to native modulo. |
spark-extension-shims-spark/src/test/scala/org/apache/auron/AuronMathCompatibilitySuite.scala |
Adds decimal remainder regression coverage with Spark-result and native-operator checks. |
Review effort: Balanced
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
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.

Which issue does this PR close?
Closes #2746
Rationale for this change
On Spark 3.4+, the decimal
%result type can be narrower than either operand. When the divisor isn't a literal, Auron cast both operands to that type before the native modulo, so an operand that didn't fit became NULL and the remainder was NULL. Arrow'sremalready rescales mixed decimal operands and returns the same result type as Spark, so the casts aren't needed.What changes are included in this PR?
NativeConverters: stop castingRemainderoperands to the result type in the non-literal-divisor branch.AuronMathCompatibilitySuite: add a test for the cases from the issue plus mixed scales, checked against Spark with a fully native plan.Are there any user-facing changes?
Native decimal
%now returns the correct remainder (matching Spark) instead of NULL in these cases. For example:a % bNULL3x % yNULL7How was this patch tested?
./dev/reformat --check: passed../build/mvn test -pl spark-extension,spark-extension-shims-spark -Ppre -Pspark-<ver> -Pscala-<scala> -DskipBuildNative -DwildcardSuites=org.apache.auron.AuronMathCompatibilitySuite: passed on Spark 3.5, 3.3 and 4.2. The new test failed before the fix.Was this patch authored or co-authored using generative AI tooling?
Generated-by: GitHub Copilot CLI 1.0.107
ASF guidance: https://www.apache.org/legal/generative-tooling.html