Skip to content

port NegativeExpr to use the try_to_proto / try_from_proto hooks#22483

Merged
adriangb merged 7 commits into
apache:mainfrom
kevinhongzl:port-negative-expr-proto-hooks
May 27, 2026
Merged

port NegativeExpr to use the try_to_proto / try_from_proto hooks#22483
adriangb merged 7 commits into
apache:mainfrom
kevinhongzl:port-negative-expr-proto-hooks

Conversation

@kevinhongzl
Copy link
Copy Markdown
Contributor

@kevinhongzl kevinhongzl commented May 23, 2026

Which issue does this PR close?

Rationale for this change

This change is part of the per-expression proto hooks migration #22418. I moved the serialization and deserialization of NegativeExpr into 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?

  • Added try_to_proto and try_from_proto to NegativeExpr
  • Removed the central NegativeExpr serialization branch
  • Updated physical_plan/from_proto.rs to route physical proto decode through try_from_proto

Are these changes tested?

Yes. This PR is verified by running

  • cargo fmt --all -- --check
  • cargo check -p datafusion-physical-expr --features proto
  • cargo check -p datafusion-proto
  • cargo test -p datafusion-proto --test proto_integration roundtrip_physical_plan
  • cargo test -p datafusion-proto --test proto_integration roundtrip_physical_expr
  • git diff --check

Are there any user-facing changes?

No user-facing changes are intended.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates proto Related to proto crate labels May 23, 2026
@adriangb
Copy link
Copy Markdown
Contributor

@kevinhongzl could you rebase and resolve conflicts please?

@kevinhongzl
Copy link
Copy Markdown
Contributor Author

@adriangb I've fixed the merge conflicts, and it's now ready to be merged.

@adriangb
Copy link
Copy Markdown
Contributor

Could you add some tests please?

Comment thread datafusion/physical-expr/src/expressions/negative.rs Outdated
@adriangb adriangb enabled auto-merge May 26, 2026 19:16
@adriangb
Copy link
Copy Markdown
Contributor

Thanks!

@adriangb adriangb disabled auto-merge May 27, 2026 14:21
@adriangb adriangb enabled auto-merge May 27, 2026 14:21
@adriangb adriangb added this pull request to the merge queue May 27, 2026
Merged via the queue into apache:main with commit c286a59 May 27, 2026
38 checks passed
@kevinhongzl
Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Port NegativeExpr to use try_to_proto / try_from_proto

2 participants