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

   ## Which issue does this PR close?
   
   - Part of [#27941](https://github.com/apache/datafusion/issues/27941).
   - Replaces [#26807](https://github.com/apache/datafusion/pull/26807) by 
@gabotechs. That branch predates 
[#26824](https://github.com/apache/datafusion/pull/26824) and I cannot push to 
it. The commit keeps Gabriel as the author.
   - Stacked on [#27968](https://github.com/apache/datafusion/pull/27968). 
Review only the last commit. I will rebase this PR and mark it ready when that 
one merges.
   
   ## Rationale for this change
   
   [#26824](https://github.com/apache/datafusion/pull/26824) gave a custom 
`DataSink` an `extension {name, payload}` arm on the wire, but nothing decodes 
that arm. A reader must still decode the whole `DataSinkExec` in a 
`PhysicalExtensionCodec`.
   
   This PR adds the decode side for sinks, in the same shape as the source 
registry in [#27968](https://github.com/apache/datafusion/pull/27968).
   
   ```rust
   impl ExtensionDataSinkFromProto for MySink {
       const NAME: &'static str = "my_crate.MySink";
   
       fn try_from_proto(
           payload: &[u8],                  // only its own state
           ctx: &ExecutionPlanDecodeCtx<'_>,
       ) -> Result<Arc<dyn DataSink>> { /* ... */ }
   }
   
   // On the worker
   config.update_extension(MySink::register_proto)?;
   ```
   
   ## What changes are included in this PR?
   
   ```diff
    decode_data_sink            # DataSinkExec rebuilds its input and sort order
      decode_sink_type
        SinkType::Json | Csv | Parquet
   -    SinkType::Extension  -> error "No decoder for extension DataSink"
   +    SinkType::Extension  -> registry lookup by name
   ```
   
   | Area | Change |
   |---|---|
   | `datafusion-datasource` | New trait `ExtensionDataSinkFromProto` with 
`NAME`, `try_from_proto` and a provided `register_proto` |
   | `datafusion-proto` | The `extension` arm looks up the name in the 
session's `ProtoDecoderRegistry` |
   | Unregistered name | A plan error that lists the registered names, sorted. 
It uses the same helper as the source arms. |
   | Upgrade guide | The 57.0.0 note covers sinks too |
   
   Differences from [#26807](https://github.com/apache/datafusion/pull/26807):
   
   | #26807 | This PR | Reason |
   |---|---|---|
   | A `PhysicalExtensionDataSinkNode` wrapper message, with `DataSinkExec` 
registered as an extension plan | Removed | The layered `data_sink` node from 
#26824 is the wrapper |
   | `extension_data_sink_node` encode helper | Removed | The sink returns the 
`extension` arm from `try_to_proto_sink` |
   | Decoder receives the proto message | Decoder receives `payload: &[u8]` | 
Review feedback on #26807 |
   | Its own "unregistered" error code | Shared helper | Review feedback on 
#26807 |
   
   New public items, behind the `proto` feature: 
`datafusion_datasource::sink::ExtensionDataSinkFromProto`. One `#[doc(hidden)]` 
function (`decode_extension_data_sink`) is `pub` only so that 
`datafusion-proto` can call it.
   
   ## What is the testing strategy for this PR?
   
   | Test file | Checks |
   |---|---|
   | `data_sink_registry.rs` (adapted from #26807) | A registered sink 
round-trips and executes: it writes `[10, 12]` and reports 2 rows. The exact 
`DataSinkNode`, the input and the sort order survive. A registered sink never 
reaches the codec. A decoder failure is returned. An unregistered name gives 
the exact error text. A codec-owned sink still uses the codec. |
   | `registry.rs` unit test | Sink names have their own scope, and registering 
twice is a no-op |
   
   ## Are there any user-facing changes?
   
   Yes, new public API (listed above). There are no breaking changes.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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