fix: preserve overflow behavior and exhaustively destructure expression proto hooks - #25034
Conversation
|
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 |
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
kosiew
left a comment
There was a problem hiding this comment.
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<()> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@peterxcli will you have time to address @kosiew 's comments before merging?
kosiew
left a comment
There was a problem hiding this comment.
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.
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 + 1raises an error before serialization but returnsInt32::MINafter 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, andSqlSimilarToPatternexplicitly 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.shsuite 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.