Skip to content

fix: [branch-1.2] preserve TRY overflow semantics in nested integer arithmetic (#7379) - #7652

Merged
andygrove merged 2 commits into
apache:branch-1.2from
andygrove:backport-7379-branch-1.2
Nov 19, 2026
Merged

andygrove merged 2 commits into
apache:branch-1.2from
andygrove:backport-7379-branch-1.2

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Backport of #7379 to branch-1.2. Closes #7378 on this branch.

Rationale for this change

With ANSI mode disabled, Spark returns NULL for try_add(a, b) + b when the inner addition overflows. branch-1.2 flattens both additions into one balanced tree that uses the outer operation's wrapping overflow behavior, so it returns a wrapped integer instead. The same problem affects try_multiply inside a multiplication. See #7379 and #7378 for the full analysis.

What changes are included in this PR?

Cherry-pick of 268ede5 (git cherry-pick -x) with no conflicts and no adaptations. Flattening in CometAdd and CometMultiply now stops at a nested Add or Multiply whose evalMode differs from the outer one, and the source PR's arithmetic.sql case is included. The diff against the source commit is identical apart from line numbers and blob hashes.

Other release branches: branch-1.2 is the newest release branch, so there is no newer one to port to.

How are these changes tested?

On this branch, with JDK 17 and the default Spark profile only: CometSqlFileTestSuite for arithmetic.sql, arithmetic_ansi.sql and arithmetic_try.sql passes against a native library built from this branch (3 tests, 0 failures). With arithmetic.scala restored to branch-1.2's version, arithmetic.sql fails (the other two still pass), so the branch has the bug and the test catches it.

sunchao and others added 2 commits November 16, 2026 10:32
…ache#7379)

* fix: preserve TRY overflow semantics in nested integer arithmetic

* docs: explain evaluation mode boundaries in arithmetic chains

(cherry picked from commit 268ede5)

@comphead comphead 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.

thanks

@andygrove
andygrove merged commit b0822ba into apache:branch-1.2 Nov 19, 2026
274 of 276 checks passed
@andygrove
andygrove deleted the backport-7379-branch-1.2 branch November 19, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants