Skip to content

feat(physical-expr): port Literal to try_to_proto / try_from_proto hooks#22636

Open
koopatroopa787 wants to merge 1 commit into
apache:mainfrom
koopatroopa787:fix/22427-literal-proto-hooks
Open

feat(physical-expr): port Literal to try_to_proto / try_from_proto hooks#22636
koopatroopa787 wants to merge 1 commit into
apache:mainfrom
koopatroopa787:fix/22427-literal-proto-hooks

Conversation

@koopatroopa787
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #22427

Rationale for this change

Literal serialization/deserialization lived in the central downcast chains in to_proto.rs and from_proto.rs. This PR moves it into self-contained try_to_proto / try_from_proto hooks on Literal itself, following the pattern established for NotExpr, NegativeExpr, IsNullExpr, and IsNotNullExpr.

What changes are included in this PR?

  • datafusion/physical-expr/src/expressions/literal.rs
    • Added #[cfg(feature = "proto")] fn try_to_proto(...) inside impl PhysicalExpr for Literal
    • Added #[cfg(feature = "proto")] impl Literal { pub fn try_from_proto(...) }
    • Added proto_tests module with encode, null-literal, roundtrip, and reject-wrong-variant tests
  • datafusion/proto/src/physical_plan/to_proto.rs
    • Removed the Literal downcast arm; removed Literal from import list
  • datafusion/proto/src/physical_plan/from_proto.rs
    • Replaced the inline ExprType::Literal arm with Literal::try_from_proto(proto, &decode_ctx)?

Are there any user-facing changes?

No. Serialization behaviour is identical; only the code location changed.

🤖 Generated with Claude Code

Move protobuf serialization/deserialization for Literal out of the
central downcast chains in to_proto.rs and from_proto.rs into
dedicated try_to_proto / try_from_proto hooks on Literal itself,
following the pattern established for NotExpr, NegativeExpr,
IsNullExpr, and IsNotNullExpr.

Closes apache#22427
Copilot AI review requested due to automatic review settings May 30, 2026 01:39
@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates proto Related to proto crate labels May 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors the protobuf serialization/deserialization of Literal physical expressions to use the per-expression try_to_proto / try_from_proto hook pattern (instead of being centrally handled in to_proto.rs / from_proto.rs).

Changes:

  • Removed the inline Literal arm from serialize_physical_expr_with_converter in to_proto.rs and dropped the unused Literal import.
  • Routed ExprType::Literal decoding through Literal::try_from_proto in from_proto.rs.
  • Added try_to_proto impl and try_from_proto constructor on Literal, plus unit tests under a proto_tests module.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
datafusion/proto/src/physical_plan/to_proto.rs Removed the inline literal serialization branch and unused Literal import.
datafusion/proto/src/physical_plan/from_proto.rs Delegates literal decoding to Literal::try_from_proto.
datafusion/physical-expr/src/expressions/literal.rs Adds try_to_proto/try_from_proto methods and proto tests for Literal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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 Literal to use try_to_proto / try_from_proto

2 participants