port NegativeExpr to use the try_to_proto / try_from_proto hooks#22483
Merged
adriangb merged 7 commits intoMay 27, 2026
Conversation
Contributor
|
@kevinhongzl could you rebase and resolve conflicts please? |
Contributor
Author
|
@adriangb I've fixed the merge conflicts, and it's now ready to be merged. |
Contributor
|
Could you add some tests please? |
adriangb
approved these changes
May 26, 2026
Contributor
|
Thanks! |
Contributor
Author
|
@adriangb Thank you so much for your patience and guidance :) |
adriangb
added a commit
to pydantic/datafusion
that referenced
this pull request
May 28, 2026
…expressions Ports the existing `try_to_proto` / `try_from_proto` implementations onto the helpers introduced in the previous commit (`expect_expr_variant!`) and the wider use of `decode_required_expression` / `decode_children_expressions` / `encode_children_expressions` from apache#22513. Covers every expression already migrated under apache#22418: - `Column`, `BinaryExpr` (originally apache#21929) - `LikeExpr` (apache#22471) - `InListExpr` (apache#22503) - `NegativeExpr` (apache#22483) `BinaryExpr` additionally switches its `l`/`r` legacy-decode arms to `decode_required_expression`, removing two more hand-rolled "missing required field" strings, and runs its `operands` encode/ decode loops through `encode_children_expressions` / `decode_children_expressions`. One existing test changes assertion text — `InListExpr`'s rejected- variant message was the only one using the article "an" instead of the macro's article-free "a"; updated to match. No wire-format change; `cargo test -p datafusion-proto --test proto_integration` is green (173 / 173).
Herrtian
pushed a commit
to Herrtian/datafusion
that referenced
this pull request
May 28, 2026
…hapes in apache#22418, port already-migrated exprs (apache#22596) ## Which issue does this PR close? Part of apache#22418 / follow-up to apache#22513. ## Rationale for this change Every PR migrating a `PhysicalExpr` to `try_to_proto` / `try_from_proto` under apache#22418 re-implements the same two shapes that don't fit the existing helpers from apache#22513: 1. The outer `match &node.expr_type { ... }` that opens every `try_from_proto`: ```rust let try_cast = match &node.expr_type { Some(protobuf::physical_expr_node::ExprType::TryCast(x)) => x.as_ref(), _ => return internal_err!("PhysicalExprNode is not a TryCastExpr"), }; ``` 2. The hand-rolled "missing required field 'X'" error for non-expression fields like `arrow_type` on `CastExpr` / `TryCastExpr`. Each shape leaks across the 7+ remaining open migration PRs. Adding small helpers in `physical-expr-common` keeps the per-expression diff minimal and the error messages consistent. ## What changes are included in this PR? **Commit 1 — `feat(physical-expr-common): add proto helpers ...`** Two new helpers in `datafusion-physical-expr-common`, both gated on `feature = "proto"`: - `expect_expr_variant!` macro (re-exported at crate root) — matches `Option<ExprType>`, returns inner payload, errors with `"PhysicalExprNode is not a {variant}"`. - `proto_decode::require_proto_field<T>(opt, expr_name, field)` — mirrors `decode_required_expression` for non-`PhysicalExprNode` fields. Five unit tests cover the helpers (success + the two reject paths for the macro). **Commit 2 — `refactor(physical-expr): adopt new proto helpers in already-migrated expressions`** Ports every expression already on the new hooks: - `Column`, `BinaryExpr` (originally apache#21929) - `LikeExpr` (apache#22471) - `InListExpr` (apache#22503) - `NegativeExpr` (apache#22483) `BinaryExpr` additionally adopts `decode_required_expression` for its legacy `l`/`r` arms and `encode_children_expressions` / `decode_children_expressions` for the linearized `operands` path, removing two more hand-rolled "missing required field" strings. One existing test changes assertion text — `InListExpr`'s rejected-variant message was the only one using the article "an" instead of "a"; the macro emits article-free "a {Variant}" uniformly. The two commits are stacked for review: commit 1 is the helper addition only; commit 2 is the adoption. Either can be reviewed in isolation. ## Are these changes tested? Yes: - `cargo test -p datafusion-physical-expr-common --features proto` — new helper unit tests pass. - `cargo test -p datafusion-physical-expr --features proto proto_tests` — 23 / 23 per-expression proto tests pass (1 assertion-string update in InList). - `cargo test -p datafusion-proto --test proto_integration` — 173 / 173 pass; no wire-format change. - `cargo clippy --all-targets --all-features -- -D warnings` clean on the touched crates. ## Are there any user-facing changes? No. New API surface in `datafusion-physical-expr-common` (helpers gated on `feature = "proto"`); no change to serialized output. The macro `expect_expr_variant!` is exported at the crate root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
NegativeExprto usetry_to_proto/try_from_proto#22426Rationale for this change
This change is part of the per-expression proto hooks migration #22418. I moved the serialization and deserialization of
NegativeExprinto its proto hooks, keeping it aligned with the new pattern used by migrated physical expressions and reducing special-case branching in the shared conversion code.What changes are included in this PR?
try_to_protoandtry_from_prototoNegativeExprNegativeExprserialization branchphysical_plan/from_proto.rsto route physical proto decode throughtry_from_protoAre these changes tested?
Yes. This PR is verified by running
cargo fmt --all -- --checkcargo check -p datafusion-physical-expr --features protocargo check -p datafusion-protocargo test -p datafusion-proto --test proto_integration roundtrip_physical_plancargo test -p datafusion-proto --test proto_integration roundtrip_physical_exprgit diff --checkAre there any user-facing changes?
No user-facing changes are intended.