NoahKusaba opened a new pull request, #27931:
URL: https://github.com/apache/datafusion/pull/27931

   ## Which issue does this PR close?
   
   - Closes #27930.
   
   ## 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 moves it upstream.
   
   ## 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 #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 #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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to