Skip to content

[AURON #2746] Fix native decimal remainder returning NULL when an operand exceeds the result type - #2748

Open
zoddtheimmortal wants to merge 1 commit into
apache:masterfrom
zoddtheimmortal:fix-decimal-remainder-null
Open

zoddtheimmortal wants to merge 1 commit into
apache:masterfrom
zoddtheimmortal:fix-decimal-remainder-null

Conversation

@zoddtheimmortal

Copy link
Copy Markdown

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's rem already 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 casting Remainder operands 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:

create table t1 (a decimal(15,0), b int, x decimal(3,0), y decimal(15,0)) using parquet;
insert into t1 values (12345678901, 7, 7, 10000000000);
select a % b, x % y from t1;
Query Before After
a % b NULL 3
x % y NULL 7

How 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?

  • Yes
  • No

Generated-by: GitHub Copilot CLI 1.0.107

ASF guidance: https://www.apache.org/legal/generative-tooling.html

Copilot AI balanced review requested due to automatic review settings November 21, 2026 10:14
@github-actions github-actions Bot added the spark label Nov 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

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.

Native decimal remainder returns NULL when an operand does not fit the result type

2 participants