Skip to content

feat: add ComposedLogicalExtensionCodec - #27931

Open
NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:composed-logical-extension-codec
Open

NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:composed-logical-extension-codec

Conversation

@NoahKusaba

@NoahKusaba NoahKusaba commented Dec 1, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

datafusion-proto can compose physical codecs with
ComposedPhysicalExtensionCodec but not logical ones, so a logical plan whose
table providers come from two independent crates can't be serialized without a
hand-written composing codec. Ballista carries its own for its Iceberg
integration (apache/datafusion-ballista#2752).

This PR is based on Ballista's codec, but changes how it handles functions,
file formats and errors, as described below. The payload layout is the same,
and Ballista's own composition (its codec, then the Iceberg codec) encodes byte
for byte the same.

What changes are included in this PR?

datafusion_proto::logical_plan::ComposedLogicalExtensionCodec, which routes
every LogicalExtensionCodec method through the composed codecs. It writes the
same DataEncoderTuple as ComposedPhysicalExtensionCodec (now pub(crate)),
so both share one payload layout.

Plan nodes and table providers work as in the physical codec: the first codec
that succeeds claims the node, even with a zero-byte encoding, and only that
codec decodes it.

The trait's default encoders for functions and file formats succeed without
writing anything, so for these the first codec that writes something wins:

  • Functions follow the approach discussed on fix: delegate the remaining codec methods in ComposedPhysicalExtensionCodec #24973. If no codec writes a
    payload, the function goes by name: it is resolved from the registry, or else
    by the first codec that can decode it.
  • File formats: if no codec writes anything, the first codec that succeeded
    claims the format. Without this rule, composing
    [MyTableCodec, DefaultLogicalExtensionCodec] breaks COPY ... TO:
    MyTableCodec claims the CSV format with zero bytes and can't decode it.

Errors:

  • if exactly one codec recognised the node (returned anything but
    NotImplemented), its error is returned unchanged;
  • otherwise every codec's error is listed, as NotImplemented when every codec
    declined, so a composed codec nested in another still declines. The wording
    matches fix: delegate the remaining codec methods in ComposedPhysicalExtensionCodec #24973's ("None of the N composed codecs could decode 'name' by
    name");
  • a payload that doesn't decode, or names a position beyond the list, is a
    configuration error saying both sides must compose the same codecs in the
    same order.

ComposedPhysicalExtensionCodec is unchanged apart from sharing the wire
struct, to avoid conflicting with #24973. Once that lands, both codecs can share
one implementation.

What is the testing strategy for this PR?

Unit tests in datafusion/proto/src/logical_plan/composed.rs cover each rule
above: position recording and position-only decoding (with codecs that would
decode any bytes), discarding a failed codec's partial write, zero-byte nodes at
position 0 and above, mismatched payloads, each error case, every kind of
function by name, and both file format cases. A COPY (SELECT upper(...)) ... STORED AS CSV plan round trips with the table, file format and function each
handled differently.

The doctest round-trips a COPY plan with a custom codec listed before the
default one.

Are there any user-facing changes?

One new public type, datafusion_proto::logical_plan::ComposedLogicalExtensionCodec.
No breaking changes.

Add the logical counterpart of ComposedPhysicalExtensionCodec, sharing
its DataEncoderTuple payload layout, so a logical plan can be serialized
with codecs from several independent crates.

The trait's default encoders for functions and file formats succeed
without writing anything, so for these the first codec that writes
something wins. A function no codec writes a payload for goes by name;
a file format no codec writes stays with the first codec that succeeded.
@github-actions github-actions Bot added the proto Related to proto crate label Dec 1, 2026
@NoahKusaba
NoahKusaba marked this pull request as ready for review December 1, 2026 22:21
@NoahKusaba

Copy link
Copy Markdown
Author

cc @milenkovicm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ComposedLogicalExtensionCodec, the logical counterpart of ComposedPhysicalExtensionCodec

1 participant