Repository navigation
feat: give PhysicalExtensionCodec the full decode context - #25318
Open
namanjain24-sudo wants to merge 26 commits into
Open
namanjain24-sudo wants to merge 26 commits into
namanjain24-sudo wants to merge 26 commits into
Conversation
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?
PhysicalExtensionCodecshould take aPhysicalPlanDecodeContextinstead of aTaskContext#25089.Rationale for this change
A custom
ExecutionPlanwhose codec decodes its own expressions fails to deserialize when one of those expressions is aScalarSubqueryExpr. It fails even when the plan sits inside theScalarSubqueryExecthat owns the results:The decoder does track the results of the enclosing
ScalarSubqueryExecinPhysicalPlanDecodeContext. ButPhysicalExtensionCodec::try_decodeonly receivesctx.task_ctx(), so a codec has to build a freshPhysicalPlanDecodeContext::new(..)to decode its expressions, and that fresh context has no results.What changes are included in this PR?
This takes the non-breaking option from the issue:
PhysicalExtensionCodec::try_decode_with_ctxreceives the fullPhysicalPlanDecodeContext. Its default implementation callstry_decode(ctx.task_ctx()), so existing codecs compile and behave as before.try_decode_with_ctx.ComposedPhysicalExtensionCodecforwardstry_decode_with_ctxto the codec that encoded the node. Without this, composing codecs would drop the context again.FFI_PhysicalExtensionCodecgains atry_decode_with_ctxfunction pointer that also forwards the caller's active scalar-subquery results scope (if any) across the boundary through a newFFI_ScalarSubqueryResultshandle, so aScalarSubqueryExprdecoded by a foreign codec shares the same populated results as the host'sScalarSubqueryExec. A codec that only implements the new method therefore also works through FFI. For codecs that only implementtry_decode, nothing changes.I went with the new method rather than changing
try_decode's signature because of the API health policy. The breaking change is simpler if reviewers prefer it, and I'm happy to switch.This touches the same function as the draft #24631, which adds a per-type registry in front of the codec. That PR's registry path already passes decoders the full context (through
ConverterPlanDecoder), but its codec fallback still callstry_decode(ctx.task_ctx()), which is the line this PR changes. Whichever lands second needs a one-line rebase.What is the testing strategy for this PR?
New tests in
datafusion/proto/tests/cases/plans/scalar_subquery.rsuse an extension plan whose codec decodes its own expressions throughtry_decode_with_ctx. Itstry_decodereturns an error, so a caller that drops the context fails the test:ScalarSubqueryExprinside the extension plan shares the enclosingScalarSubqueryExec's results, with bothDefaultPhysicalProtoConverterandDeduplicatingProtoConverterComposedPhysicalExtensionCodecScalarSubqueryExecs: each expression binds to its own scope and not to the otherScalarSubqueryExec, decoding still fails with the existing errorA new FFI test checks that a codec that only decodes through
try_decode_with_ctxworks behindFFI_PhysicalExtensionCodec. A second, cross-library integration test (datafusion/ffi/tests/ffi_physical_extension_codec.rs, gated by theintegration-testsfeature) builds that codec inside a separatelydlopen'd copy of thedatafusion-fficdylib, so the scalar-subquery results handle crosses a genuine FFI boundary and exercisesForeignScalarSubqueryResultsBackendfor real, rather than only the in-processmock_foreign_marker_idpath the unit test uses.I checked that each part of the change is needed:
mainwith the error from the issue.try_decode, all four new proto tests fail.ComposedPhysicalExtensionCodec::try_decode_with_ctxremoved, only the composed-codec test fails.Existing suites pass:
datafusion-proto(17 lib, 265 integration, 4 doc tests) anddatafusion-ffi(123 lib tests, plus the new cross-library test under--features integration-tests)../dev/rust_lint.shis clean.Are there any user-facing changes?
This has two separate kinds of API impact:
PhysicalExtensionCodec::try_decode_with_ctxis a new provided method. Existing implementations keep compiling and behave the same.FFI_PhysicalExtensionCodecis#[repr(C)]and gains atry_decode_with_ctxfunction-pointer field, appended after the existing fields so a producer compiled against the old layout still sees every field it knows about at its original offset. The struct's size still changes, so this is an ABI break: a producer and a consumer built against different layouts of this struct must not be mixed — both sides need to be rebuilt against the same DataFusion version. This should carry theapi changelabel; I don't have permission to add labels on this repo, so flagging it here for a maintainer to apply.The same two-sided split applies to the
FFI_ScalarSubqueryResultshandle added for the scalar-subquery results forwarding described above.