adriangb opened a new issue, #27941:
URL: https://github.com/apache/datafusion/issues/27941

   ### Is your feature request related to a problem or challenge?
   
   **Who this is for:** people who ship physical plans between processes (for 
example, distributed engines built on `datafusion-proto`) and who have their 
own `DataSource`, `FileSource` or `DataSink` types. Users of only the built-in 
Parquet/CSV/JSON/Avro/Arrow sources are not affected.
   
   **Example:** a distributed engine scans a file format that is not part of 
DataFusion. `VortexSource` implements `FileSource`. The coordinator must send 
the scan to the workers.
   
   `VortexSource` has one piece of its own state (a pushed-down predicate). 
Today its hook must still produce the whole plan node, including everything 
that `FileScanConfig` owns:
   
   ```rust
   impl FileSource for VortexSource {
       fn try_to_proto(&self, base: &FileScanConfig, ctx: 
&ExecutionPlanEncodeCtx<'_>)
           -> Result<Option<PhysicalPlanNode>>
       {
           // Must carry the shared config (files, projection, statistics, 
limit) itself
           let my_msg = MyVortexScan {
               base_conf: Some(base.try_to_proto(ctx)?),
               predicate: self.encode_predicate(ctx)?,
           };
           // ...and wrap it in a plan-level extension node
           Ok(Some(PhysicalPlanNode { /* extension { node: my_msg bytes } */ }))
       }
   }
   ```
   
   On the worker, a `PhysicalExtensionCodec` must recognize those bytes among 
every other extension plan, rebuild the `FileScanConfig`, and wrap it in a 
`DataSourceExec`.
   
   | Problem | Effect |
   |---|---|
   | The source writes state that it does not own | Each custom source copies 
the `FileScanConfig` and `DataSourceExec` wire logic, and breaks when that 
logic changes |
   | The wire format has no slot for "a `FileSource`" or "a `DataSink`" | A 
custom type can only appear as a whole-plan extension node |
   | Decode goes through one `PhysicalExtensionCodec` | An application that 
combines sources from several libraries must compose their codecs 
([#24331](https://github.com/apache/datafusion/issues/24331)) |
   
   ### Describe the solution you'd like
   
   The source describes only itself, and DataFusion writes the wrappers:
   
   ```rust
   impl FileSource for VortexSource {
       fn try_to_proto_file_source(&self, ctx: &ExecutionPlanEncodeCtx<'_>)
           -> Result<Option<FileSourceNode>>
       {
           Ok(Some(FileSourceNode {
               file_source_type: 
Some(FileSourceType::Extension(ExtensionFileSourceNode {
                   name: "vortex".into(),
                   payload: self.encode_predicate(ctx)?, // only its own state
               })),
           }))
       }
   }
   ```
   
   On the worker, `VortexSource` registers a decoder under the name `"vortex"`. 
The decoder receives only the payload. No `PhysicalExtensionCodec` is needed. 
The same applies to a custom `DataSource` and a custom `DataSink`.
   
   Work items:
   
   - [ ] Wire format with one message per trait level, and the encode hooks: 
[#26824](https://github.com/apache/datafusion/pull/26824)
   - [ ] Decode an extension `DataSource` / `FileSource` through a per-type 
registry: [#26555](https://github.com/apache/datafusion/pull/26555)
   - [ ] Decode an extension `DataSink` through a per-type registry: 
[#26807](https://github.com/apache/datafusion/pull/26807)
   - [ ] An example in `datafusion-examples` that serializes and deserializes a 
custom source
   - [ ] Link that example from the 57.0.0 upgrade guide
   
   ### Describe alternatives you've considered
   
   Keep the whole-plan hooks and give custom sources public helpers that build 
the wrapper node. This keeps two ways to serialize a source, and a source can 
still return any plan variant.
   
   ### Additional context
   
   This continues the per-type registry work for extension `ExecutionPlan`s 
([#24625](https://github.com/apache/datafusion/issues/24625)) and extension 
`PhysicalExpr`s ([#24626](https://github.com/apache/datafusion/issues/24626)).
   


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