Commit fcc9cc4
refactor(physical-expr): add proto ctx expr helpers and adopt in InList/Like (apache#22513)
## Which issue does this PR close?
- Part of apache#22418 (decentralizing `datafusion-proto` serialization onto
the expressions themselves; follows apache#21835, apache#22471, apache#22503).
## Rationale for this change
Expressions migrating to the `try_to_proto` / `try_from_proto` hooks
keep hand-rolling the same boilerplate that the central
`datafusion-proto` match already factors out via `parse_physical_exprs`,
`parse_required_physical_expr`, and `serialize_physical_exprs`. Those
free functions can't be reused by expression authors: they take
`PhysicalProtoConverterExtension` / `PhysicalPlanDecodeContext`, which
the `PhysicalExprEncodeCtx` / `PhysicalExprDecodeCtx` surfaces
deliberately hide.
This was raised in review on apache#22503 — rather than re-implement the list
maps and "missing required field" checks in every migrated expression,
expose the same shapes on the ctx structs.
## What changes are included in this PR?
- **`datafusion-physical-expr-common`**: three thin convenience methods,
built on the existing `encode_child` / `decode` primitives:
- `PhysicalExprEncodeCtx::encode_children_expressions`
- `PhysicalExprDecodeCtx::decode_required_expression` (also standardizes
the `Missing required field "<name>"` error so each expression no longer
spells its own)
- `PhysicalExprDecodeCtx::decode_children_expressions`
- **`datafusion-physical-expr`**: adopt them in `InListExpr` and
`LikeExpr`, removing the hand-rolled list maps and per-field
`ok_or_else` checks.
### Behavior note
`decode_required_expression` couples the presence check with the decode,
so `LikeExpr` now decodes children left-to-right rather than validating
both required fields up front. The end result is unchanged (a missing
required field still errors), but a present sibling is decoded before a
later missing field is reported. The
`try_from_proto_rejects_missing_pattern` unit test is updated to reflect
this.
## Are these changes tested?
Yes — covered by existing tests, no new ones needed:
- The isolated `proto_tests` modules in `in_list.rs` and `like.rs`
already exercise all three helpers (list encode/decode, required decode,
and the missing-field + child-error paths) through the migrated
`try_to_proto` / `try_from_proto`.
- The `datafusion-proto` round-trip integration tests
(`roundtrip_inlist`, `roundtrip_like`,
`roundtrip_filter_with_not_and_in_list`,
`test_tpch_part_in_list_query_with_real_parquet_data`, etc.) continue to
pass.
- `cargo clippy --all-targets --features proto -D warnings` is clean on
the touched crates; `cargo fmt --all` applied.
## Are there any user-facing changes?
No. The per-expression `missing required field` error wording is
preserved: `LikeExpr` is byte-for-byte identical, and `InList` only
changes its label from `InList` to `InListExpr` (the actual type name).
The format now lives in one place (`decode_required_expression`) instead
of being hand-spelled per expression.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1b8451c commit fcc9cc4
3 files changed
Lines changed: 73 additions & 31 deletions
File tree
- datafusion
- physical-expr-common/src
- physical-expr/src/expressions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
559 | 577 | | |
560 | 578 | | |
561 | 579 | | |
| |||
636 | 654 | | |
637 | 655 | | |
638 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
639 | 694 | | |
640 | 695 | | |
641 | 696 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
277 | 269 | | |
278 | 270 | | |
279 | 271 | | |
| |||
491 | 483 | | |
492 | 484 | | |
493 | 485 | | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
| 486 | + | |
499 | 487 | | |
500 | 488 | | |
501 | 489 | | |
| |||
4007 | 3995 | | |
4008 | 3996 | | |
4009 | 3997 | | |
4010 | | - | |
| 3998 | + | |
4011 | 3999 | | |
4012 | 4000 | | |
4013 | 4001 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 193 | | |
205 | 194 | | |
206 | 195 | | |
207 | | - | |
208 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
209 | 206 | | |
210 | 207 | | |
211 | 208 | | |
| |||
491 | 488 | | |
492 | 489 | | |
493 | 490 | | |
494 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
495 | 494 | | |
496 | 495 | | |
497 | 496 | | |
| |||
0 commit comments