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

   ## Which issue does this PR close?
   
   - Part of [#27941](https://github.com/apache/datafusion/issues/27941).
   - Replaces [#26555](https://github.com/apache/datafusion/pull/26555) 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.
   
   ## Rationale for this change
   
   [#26824](https://github.com/apache/datafusion/pull/26824) gave a custom 
`DataSource` or `FileSource` an `extension {name, payload}` arm on the wire, 
but nothing decodes that arm. A reader must still decode the whole 
`DataSourceExec` in a `PhysicalExtensionCodec`.
   
   This PR adds the decode side: a per-type registry, in the same shape as 
`ExtensionPlanFromProto` and `ExtensionExprFromProto`.
   
   ```rust
   impl ExtensionFileSourceFromProto for VortexSource {
       const NAME: &'static str = "vortex.VortexSource";
   
       fn try_from_proto(
           payload: &[u8],                  // only its own state
           table_schema: &TableSchema,
           ctx: &ExecutionPlanDecodeCtx<'_>,
       ) -> Result<Arc<dyn FileSource>> { /* ... */ }
   }
   
   // On the worker
   config.update_extension(VortexSource::register_proto)?;
   ```
   
   ## What changes are included in this PR?
   
   ```diff
    decode_data_source
      SourceType::File
        decode_file_scan
          FileSourceType::Parquet | Csv | Json | Avro | Arrow
   -      FileSourceType::Extension  -> error "No decoder for extension 
FileSource"
   +      FileSourceType::Extension  -> registry lookup by name -> 
FileScanConfig around the result
      SourceType::Memory
   -  SourceType::Extension          -> error "No decoder for extension 
DataSource"
   +  SourceType::Extension          -> registry lookup by name -> 
DataSourceExec around the result
   ```
   
   | Area | Change |
   |---|---|
   | `datafusion-datasource` | New traits `ExtensionDataSourceFromProto` and 
`ExtensionFileSourceFromProto`, each with `NAME`, `try_from_proto` and a 
provided `register_proto` |
   | `datafusion-proto` | The two `extension` arms look up the name in the 
session's `ProtoDecoderRegistry` |
   | Unregistered name | A plan error that lists the registered names, sorted |
   | Upgrade guide | The 57.0.0 note describes how to decode the `extension` 
arm |
   
   Differences from [#26555](https://github.com/apache/datafusion/pull/26555):
   
   | #26555 | This PR | Reason |
   |---|---|---|
   | A `PhysicalExtensionDataSourceNode` wrapper message, with `DataSourceExec` 
registered as an extension plan | Removed | The layered `data_source` node from 
#26824 is the wrapper |
   | `extension_data_source_node` encode helper | Removed | The source returns 
the `extension` arm from `try_to_proto_source` |
   | Decoder receives the proto message | Decoder receives `payload: &[u8]` | 
Review feedback on #26555 |
   | `DataSource` only | `DataSource` and `FileSource` | Most custom sources 
are file sources. Review feedback on #26555. |
   
   One design choice to check: the `FileSource` decoder receives the 
`TableSchema` parsed from the shared scan config, not the raw 
`FileScanExecConf`. This keeps proto structure out of the public trait.
   
   New public items, all behind the `proto` feature: 
`datafusion_datasource::source::ExtensionDataSourceFromProto` and 
`datafusion_datasource::file::ExtensionFileSourceFromProto`. Two 
`#[doc(hidden)]` functions (`decode_extension_data_source`, 
`decode_extension_file_source`) are `pub` only so that `datafusion-proto` can 
call them.
   
   ## What is the testing strategy for this PR?
   
   | Test file | Checks |
   |---|---|
   | `data_source_registry.rs` (adapted from #26555) | A registered source 
round-trips and executes. A registered source never reaches the codec. A 
decoder failure is returned, not passed to the codec. An unregistered name 
gives the exact error text. A codec-owned source still uses the codec. |
   | `data_source_registry.rs`, file source cases (new) | Round trip with the 
exact `FileSourceNode`, table schema and file path. Unregistered name. Decoder 
failure. |
   | `registry.rs` unit tests | Registering twice is a no-op. Name collision 
and empty name are errors. `DataSource` and `FileSource` names have separate 
scopes. |
   
   ## 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