Skip to content

fix: preserve overflow behavior and exhaustively destructure expression proto hooks - #25034

Merged
kosiew merged 4 commits into
apache:mainfrom
peterxcli:fix/physical-expr-proto-overflow
Sep 22, 2026
Merged

kosiew merged 4 commits into
apache:mainfrom
peterxcli:fix/physical-expr-proto-overflow

Conversation

@peterxcli

@peterxcli peterxcli commented Sep 7, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #24614.

Rationale for this change

This PR fixes serialization losing the setting that makes arithmetic fail on overflow. For example, checked Int32::MAX + 1 raises an error before serialization but returns Int32::MIN after decoding. Preserving this setting ensures that sending an expression through protobuf preserves its arithmetic behavior.

What changes are included in this PR?

The protobuf message now stores BinaryExpr::fail_on_overflow, and both supported decoding formats restore it. When the encoder combines nested expressions into a flat list of operands, it requires their operators and overflow settings to match. This preserves the behavior of expressions that mix checked and wrapping arithmetic. The generated Rust and JSON bindings include the new field.

All six encoding and decoding hooks for BinaryExpr, LikeExpr, and SqlSimilarToPattern explicitly list every field without a rest pattern. Adding a field to an expression or its protobuf payload will cause a compile error until the corresponding hook handles it.

The PR also changes the PostgreSQL SQLLogicTest decimal formatter to borrow its argument, resolving an existing Clippy error that blocked the required checks before committing.

What is the testing strategy for this PR?

The new tests serialize and decode nested additions, then check their evaluated results for all four combinations of checked and wrapping arithmetic. The regression test failed before the fix because an expression that should raise an overflow error returned Int32(-2147483648). Additional tests cover older messages that omit the new field and verify that JSON preserves the overflow setting.

All 17 focused expression tests passed. The extended workspace run passed 11,260 Rust tests, with 8 ignored, and completed all 511 SQLLogicTest files. Both conversion tests passed with the PostgreSQL feature enabled. Formatting, Clippy with all targets and features, and the complete ./dev/rust_lint.sh suite also passed.

Are there any user-facing changes?

Expressions configured to fail on arithmetic overflow now raise the expected error after serialization and decoding, including nested expressions with different overflow settings.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) proto Related to proto crate labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-physical-expr v55.1.0 (current)
       Built [  30.522s] (current)
     Parsing datafusion-physical-expr v55.1.0 (current)
      Parsed [   0.050s] (current)
    Building datafusion-physical-expr v55.1.0 (baseline)
       Built [  30.334s] (baseline)
     Parsing datafusion-physical-expr v55.1.0 (baseline)
      Parsed [   0.051s] (baseline)
    Checking datafusion-physical-expr v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.343s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  62.296s] datafusion-physical-expr
    Building datafusion-proto v55.1.0 (current)
       Built [  57.030s] (current)
     Parsing datafusion-proto v55.1.0 (current)
      Parsed [   0.018s] (current)
    Building datafusion-proto v55.1.0 (baseline)
       Built [  56.952s] (baseline)
     Parsing datafusion-proto v55.1.0 (baseline)
      Parsed [   0.019s] (baseline)
    Checking datafusion-proto v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   0.114s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 115.490s] datafusion-proto
    Building datafusion-proto-models v55.1.0 (current)
       Built [  26.776s] (current)
     Parsing datafusion-proto-models v55.1.0 (current)
      Parsed [   0.138s] (current)
    Building datafusion-proto-models v55.1.0 (baseline)
       Built [  26.311s] (baseline)
     Parsing datafusion-proto-models v55.1.0 (baseline)
      Parsed [   0.134s] (baseline)
    Checking datafusion-proto-models v55.1.0 -> v55.1.0 (no change; assume patch)
     Checked [   1.881s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip

--- failure constructible_struct_adds_field: struct exhaustively constructible through public API adds field ---

Description:
A pub struct that could be exhaustively constructed with a literal using only public API has a new pub field, breaking existing exhaustive literals.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field PhysicalBinaryExprNode.fail_on_overflow in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1841
  field PhysicalBinaryExprNode.fail_on_overflow in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1841

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  56.311s] datafusion-proto-models

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Sep 7, 2026
@codecov-commenter

codecov-commenter commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.76471% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.42%. Comparing base (0576a0b) to head (6841655).

Files with missing lines Patch % Lines
datafusion/physical-expr/src/expressions/binary.rs 84.84% 1 Missing and 4 partials ⚠️
datafusion/proto-models/src/generated/pbjson.rs 69.23% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25034      +/-   ##
==========================================
- Coverage   82.42%   82.42%   -0.01%     
==========================================
  Files        1139     1139              
  Lines      435372   435406      +34     
  Branches   435372   435406      +34     
==========================================
+ Hits       358845   358871      +26     
+ Misses      54826    54824       -2     
- Partials    21701    21711      +10     

☔ 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.

@peterxcli
peterxcli marked this pull request as draft September 7, 2026 22:53
@peterxcli peterxcli changed the title fix: preserve binary expression overflow policy in protobuf fix: preserve overflow behavior and exhaustively destructure expression proto hooks Sep 8, 2026
@peterxcli
peterxcli marked this pull request as ready for review September 8, 2026 01:25

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

@peterxcli,

Thanks for working on this. The overflow policy now looks properly preserved across protobuf roundtrips, including cases where flattened binary-expression chains have different overflow policies.

I only have one non-blocking suggestion around JSON coverage.


#[test]
#[cfg(feature = "json")]
fn roundtrip_binary_expr_overflow_legacy() -> Result<()> {

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.

Could we also add a JSON roundtrip case for the current flattened operands representation with failOnOverflow: true? Right now this test covers JSON through the legacy l/r shape, while normal encoding emits operands. Covering that form would exercise the updated pbjson handling through the same representation used by current production encoding.

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.

@peterxcli will you have time to address @kosiew 's comments before merging?

@peterxcli
peterxcli requested review from alamb and kosiew September 20, 2026 11:43
@github-actions github-actions Bot removed the sqllogictest SQL Logic Tests (.slt) label Sep 20, 2026

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

@peterxcli,

Thanks for the follow-up. The new JSON round-trip test addresses the earlier coverage suggestion. It checks the current flattened operands representation, verifies that failOnOverflow is serialized, and confirms that checked overflow behavior is preserved after JSON decoding.

I also checked the merge commit and did not find any additional PR-side changes or new issues.

Looks good to me.

@kosiew
kosiew added this pull request to the merge queue Sep 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 21, 2026
@alamb
alamb enabled auto-merge September 21, 2026 19:23
@alamb
alamb added this pull request to the merge queue Sep 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 21, 2026
@kosiew
kosiew added this pull request to the merge queue Sep 22, 2026
Merged via the queue into apache:main with commit 714956b Sep 22, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api change Auto detected API change physical-expr Changes to the physical-expr crates proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destructure proto hooks for binary and pattern physical expressions

4 participants