adriangb opened a new pull request, #28004: URL: https://github.com/apache/datafusion/pull/28004
## Which issue does this PR close? - Part of [#27941](https://github.com/apache/datafusion/issues/27941): the last two items of its checklist (the example, and the link from the upgrade guide). ## Rationale for this change Extension expressions, plans and file sources each have a per-type decoder trait (`ExtensionExprFromProto`, `ExtensionPlanFromProto`, `ExtensionFileSourceFromProto`). No example shows them together, and no example shows what a library should export so that an application can register all of its types in one call. ## What changes are included in this PR? A new `extension_crate` example in the `proto` examples. The `numbers_crate` module stands in for a crate outside DataFusion: ```text RepeatExec: times=2 <- custom ExecutionPlan ProjectionExec: [ScaleExpr(value)] <- custom PhysicalExpr in a built-in plan DataSourceExec <- built-in, written by DataFusion FileScanConfig <- built-in, written by DataFusion NumbersSource <- custom FileSource ``` The crate exports one function that registers every decoder: ```rust pub fn register_all(config: &mut SessionConfig) -> Result<()> { config.update_extension(|registry: &mut ProtoDecoderRegistry| { ScaleExpr::register_proto(registry)?; RepeatExec::register_proto(registry)?; NumbersSource::register_proto(registry) }) } ``` It takes `&mut SessionConfig` because the decoders live there and every way to build a session has one. The example also calls it on an existing `SessionContext`, through `ctx.state_ref().write().config_mut()`. | Commit | Content | |---|---| | 1 | Re-export `datafusion_datasource::file` as `datafusion::datasource::file` | | 2 | The example, the generated examples README, and the link from the 57.0.0 upgrade guide | Commit 1 is needed because examples use only the `datafusion` crate. `ExtensionDataSourceFromProto` and `ExtensionDataSinkFromProto` are reachable through the re-exported `source` and `sink` modules, but `ExtensionFileSourceFromProto` is not, because `file` is not re-exported. ## What is the testing strategy for this PR? The example checks itself, and CI runs it: | Step | Check | |---|---| | Decode in a session that only called `register_all` | The decoded plan displays the same as the original | | Execute the decoded plan against a real file | The exact rows: `10, 20, 30, 10, 20, 30` | | Decode in an existing `SessionContext` after `register_all` | The decoded plan displays the same as the original | | Decode in a session that did not register | The error contains `No decoder is registered` | ```bash cargo run --example proto -- extension_crate ``` ## Are there any user-facing changes? One new public path: `datafusion::datasource::file` (a re-export of `datafusion_datasource::file`). 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]
