refactor: Migrate ScalarSubqueryExpr to self-serialization proto pattern#23130
Open
mattp5657 wants to merge 1 commit into
Open
refactor: Migrate ScalarSubqueryExpr to self-serialization proto pattern#23130mattp5657 wants to merge 1 commit into
mattp5657 wants to merge 1 commit into
Conversation
Move ScalarSubqueryExpr proto encode/decode into the expression itself via the try_to_proto / try_from_proto hooks, removing the centralized downcast branch in to_proto.rs and the inline construction in from_proto.rs. Because the ScalarSubqueryResults container is runtime-only shared state and not part of the wire format, from_proto.rs still fetches it from the decode context and threads it into try_from_proto. Follows the pattern established in apache#21929.
690d82c to
4abb2f5
Compare
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.
Move ScalarSubqueryExpr proto encode/decode into the expression itself via the try_to_proto / try_from_proto hooks, removing the centralized downcast branch in to_proto.rs and the inline construction in from_proto.rs. Because the ScalarSubqueryResults container is runtime-only shared state and not part of the wire format, from_proto.rs still fetches it from the decode context and threads it into try_from_proto.
Follows the pattern established in #21929.
Which issue does this PR close?
Rationale for this change
datafusion-proto serializes ScalarSubqueryExpr by downcasting in to_proto.rs and rebuilding it inline in from_proto.rs, which forces its internal fields to be exposed as public accessors just for the proto crate.
PR #21929 introduced a self-serialization pattern (try_to_proto / try_from_proto) where each expression owns its own wire format and the central dispatch just delegates. Other expressions like InListExpr and DynamicFilterPhysicalExpr already use it. This change moves ScalarSubqueryExpr to the same pattern, removing its bespoke proto branches and the proto-only public accessors.
One wrinkle: ScalarSubqueryExpr's ScalarSubqueryResults is runtime-only shared state, not part of the wire format, so try_from_proto takes it as an extra argument that from_proto.rs threads in from the decode context.
What changes are included in this PR?
try_to_protoinimpl PhysicalExpr for ScalarSubqueryExpr(not inherent),#[cfg(feature = "proto")]ScalarSubqueryExpr::try_from_protowired intofrom_proto.rsto_proto.rs+from_proto.rsarms deleted in this PR-D warningsclean; PR template filled inAre these changes tested?
scalar_subquery.rs,#[cfg(all(test, feature = "proto"))]module at end of file) exercise the hooks directly:round_trips_through_proto— encode viatry_to_proto, decode viatry_from_proto, assertingdata_type/nullable/indexand shared-results identity survive.rejects_non_scalar_subquery_node— wrongExprTypevariant errors cleanly.rejects_missing_data_type— missing required field errors cleanly.datafusion-proto,--all-features) cover the full plan path:roundtrip_scalar_subquery_exec,roundtrip_nested_scalar_subquery_exec_scopes_results, androundtrip_scalar_subquery_exec_with_default_converter_executes.All pass, and
cargo fmt --all+cargo clippy --all-features --all-targets -- -D warningsare clean.Are there any user-facing changes?
No