Skip to content

fix(spark): match Spark abs overflow errors - #24156

Merged
kosiew merged 3 commits into
apache:mainfrom
goutamadwant:fix-spark-abs-overflow
Aug 19, 2026
Merged

kosiew merged 3 commits into
apache:mainfrom
goutamadwant:fix-spark-abs-overflow

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When ANSI mode is enabled, datafusion-spark reports type-specific DataFusion errors for integral abs overflow. The scalar and array paths also produce different messages. Spark 4.2 uses one canonical ARITHMETIC_OVERFLOW message for both paths.

What changes are included in this PR?

  • Add a Spark-local checked abs array kernel so Spark-specific error text does not change core DataFusion behavior.
  • Use the Spark 4.2 ARITHMETIC_OVERFLOW message for scalar and array overflows.
  • Update the existing Spark SQL logic tests for all signed integer widths and both input shapes.

Are these changes tested?

Yes. The following checks pass:

  • cargo fmt --all -- --check
  • cargo clippy -p datafusion-spark --all-targets --all-features -- -D warnings
  • cargo test -p datafusion-spark --all-features
  • cargo test --profile=ci --test sqllogictests -- spark/math/abs.slt
  • cargo test --profile=ci --test sqllogictests -- math.slt
  • RUST_BACKTRACE=1 cargo test --profile ci --exclude datafusion-examples --exclude datafusion-benchmarks --exclude datafusion-cli --workspace --lib --tests --bins --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption

Are there any user-facing changes?

Yes. With datafusion.execution.enable_ansi_mode = true, Spark abs overflow errors now use Spark 4.2's canonical ARITHMETIC_OVERFLOW message for scalar and array inputs. There are no public API changes.

@codecov-commenter

codecov-commenter commented Aug 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.25%. Comparing base (6eaca8b) to head (40c26c8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24156      +/-   ##
==========================================
- Coverage   81.26%   81.25%   -0.01%     
==========================================
  Files        1112     1112              
  Lines      391578   391574       -4     
  Branches   391578   391574       -4     
==========================================
- Hits       318197   318190       -7     
+ Misses      54677    54673       -4     
- Partials    18704    18711       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

@goutamadwant,

Thanks for working on this. The change looks good overall. I like that the scalar and array paths now use the same Spark 4.2 ARITHMETIC_OVERFLOW error contract, and the SQLLogicTests cover the signed integral types consistently.

I left one small non-blocking suggestion to simplify the array helper.

let array = downcast_named_arg!(&input, "abs arg", $ARRAY_TYPE);
let res: $ARRAY_TYPE = array
.try_unary(|x| x.checked_abs().ok_or_else(arithmetic_overflow_error))
.and_then(|v| Ok(v.with_data_type(input.data_type().clone())))?;

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.

Small suggestion: could we use .map(|v| v.with_data_type(...))? here instead of .and_then(|v| Ok(v.with_data_type(...)))?? Since with_data_type is infallible, map feels a little simpler and makes the intent clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kosiew addressed this. thanks for checkign!

Compare the stable DataFusion error text after stripping optional backtrace output so the test passes with the CI backtrace feature enabled.

Signed-off-by: goutamadwant <[email protected]>
@goutamadwant
goutamadwant force-pushed the fix-spark-abs-overflow branch from 434be0b to 40c26c8 Compare August 18, 2026 04:39
@goutamadwant

Copy link
Copy Markdown
Contributor Author

thanks for checking @kosiew addressed the comment - let me know if you have any more comments / suggestions. thanks!

@kosiew
kosiew added this pull request to the merge queue Aug 19, 2026
@kosiew

kosiew commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Thanks @goutamadwant for working on this 👍

Merged via the queue into apache:main with commit 76a4513 Aug 19, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spark Changes to datafusion-spark crate sqllogictest SQL Logic Tests (.slt) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] abs reports a DataFusion-specific ANSI overflow message instead of Spark's ARITHMETIC_OVERFLOW text

4 participants