Skip to content

fix(ffi): use the session's LogicalExtensionCodec in create_physical_plan - #24690

Merged
timsaucer merged 1 commit into
apache:mainfrom
timsaucer:fix-ffi-session-create-physical-plan-codec
Aug 26, 2026
Merged

fix(ffi): use the session's LogicalExtensionCodec in create_physical_plan#24690
timsaucer merged 1 commit into
apache:mainfrom
timsaucer:fix-ffi-session-create-physical-plan-codec

Conversation

@timsaucer

@timsaucer timsaucer commented Aug 26, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

A foreign library that holds an FFI session reference cannot call Session::create_physical_plan for any plan that references a custom table provider or other extension node. Planning fails with:

This feature is not implemented: LogicalExtensionCodec is not provided

What changes are included in this PR?

In datafusion/ffi/src/session/mod.rs, we now serialize and deserialize logical plans using codecs. This matches what optimize_fn_wrapper and ForeignSession::optimize already do.

Are these changes tested?

Yes. A new unit test,
session::tests::test_create_physical_plan_uses_logical_codec, registers a MemTable that can only be serialized by a custom codec, wraps the session in an FFI_SessionRef carrying that codec, and plans a scan of it through
ForeignSession::create_physical_plan.

The test was verified to reproduce the bug: with either half of the fix reverted it fails.

Are there any user-facing changes?

No API changes. Session::create_physical_plan over FFI now works for plans that require the session's LogicalExtensionCodec instead of returning a not-implemented error. No breaking changes.

…plan

`Session::create_physical_plan` was the one method on `FFI_SessionRef` that
never consulted the session's `logical_codec`. Both sides of the boundary
serialized the logical plan with the codec-less helpers:
`ForeignSession::create_physical_plan` called `logical_plan_to_bytes` and
`create_physical_plan_fn_wrapper` called `logical_plan_from_bytes`.

As a result, a foreign library holding an `FFI_SessionRef` could not call
`create_physical_plan` for any plan referencing a custom table provider or
other extension node. Serialization failed with "This feature is not
implemented: LogicalExtensionCodec is not provided", even though the
neighboring `optimize` path already used the codec-aware helpers.

Both sides now use `logical_plan_to_bytes_with_extension_codec` and
`logical_plan_from_bytes_with_extension_codec`. In the wrapper the codec is
extracted before `session.inner()` shadows the binding.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the ffi Changes to the ffi crate label Aug 26, 2026
@timsaucer
timsaucer marked this pull request as ready for review August 26, 2026 12:03
@timsaucer
timsaucer enabled auto-merge August 26, 2026 12:09
@timsaucer
timsaucer added this pull request to the merge queue Aug 26, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.45%. Comparing base (66a901f) to head (d22a37d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/ffi/src/session/mod.rs 75.00% 0 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24690      +/-   ##
==========================================
- Coverage   81.45%   81.45%   -0.01%     
==========================================
  Files        1119     1119              
  Lines      400045   400069      +24     
  Branches   400045   400069      +24     
==========================================
+ Hits       325859   325874      +15     
- Misses      55146    55148       +2     
- Partials    19040    19047       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Merged via the queue into apache:main with commit 46f8df1 Aug 26, 2026
40 checks passed
@timsaucer
timsaucer deleted the fix-ffi-session-create-physical-plan-codec branch August 26, 2026 12:29
alamb pushed a commit that referenced this pull request Aug 26, 2026
…te_physical_plan (#24690) (#24694)

This PR is a cherry-pick of #24690 onto `branch-55`. See the original PR
for a description of the issue.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ffi Changes to the ffi crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session::create_physical_plan over FFI ignores the session's LogicalExtensionCodec

3 participants