Repository navigation
Conversation
748f78a to
56a3c63
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Deprecated encoders now emit layered nodes that their paired decoders reject, breaking existing source and sink round trips and requiring decoder compatibility fixes and tests.
1 open issue
What changed in this PR
This PR introduces layered protobuf nodes that mirror DataFusion’s source and sink traits, preparing for the per-type decoder registries in #26555 and #26807.
Changes:
- Adds source, file-source, and sink messages and migrates built-in encoding to the layered format.
- Retains legacy decoding and deprecated hooks while centralizing compatibility conversions.
- Adds compatibility tests and documents migration and reader/writer version constraints.
| File | Description |
|---|---|
docs/source/library-user-guide/upgrading/56.0.0.md |
Documents deprecated hooks and wire-format migration. |
datafusion/proto/tests/cases/plans/sources.rs |
Updates source assertions for layered nodes. |
datafusion/proto/tests/cases/plans/sinks.rs |
Updates sink assertions for layered nodes. |
datafusion/proto/tests/cases/plans/mod.rs |
Registers compatibility tests. |
datafusion/proto/tests/cases/plans/legacy.rs |
Tests layered encoding, legacy decoding, and fallback behavior. |
datafusion/proto/src/physical_plan/mod.rs |
Dispatches layered and legacy source/sink decoding. |
datafusion/proto-models/src/physical_plan_compat.rs |
Maps legacy scan fields into source messages. |
datafusion/proto-models/src/lib.rs |
Exposes compatibility conversions. |
datafusion/proto-models/src/generated/prost.rs |
Adds generated layered protobuf types. |
datafusion/proto-models/proto/datafusion.proto |
Defines layered messages and retains legacy variants. |
datafusion/datasource/src/source.rs |
Adds source-level encoding and wrapper construction. |
datafusion/datasource/src/sink.rs |
Adds sink-level encoding and wrapper construction. |
datafusion/datasource/src/memory.rs |
Migrates memory-source serialization. |
datafusion/datasource/src/file.rs |
Adds file-source encoding with deprecated-hook forwarding. |
datafusion/datasource/src/file_scan_config/mod.rs |
Combines shared scan configuration with source messages. |
datafusion/datasource-parquet/src/source.rs |
Migrates Parquet source serialization. |
datafusion/datasource-parquet/src/sink.rs |
Migrates Parquet sink encoding. |
datafusion/datasource-json/src/source.rs |
Migrates JSON source serialization. |
datafusion/datasource-json/src/file_format.rs |
Migrates JSON sink encoding. |
datafusion/datasource-csv/src/source.rs |
Migrates CSV source serialization. |
datafusion/datasource-csv/src/file_format.rs |
Migrates CSV sink encoding. |
datafusion/datasource-avro/src/source.rs |
Migrates Avro source serialization. |
datafusion/datasource-arrow/src/source.rs |
Migrates Arrow source serialization. |
Review effort: Balanced
a50ac0d to
da361cb
Compare
da361cb to
009fa28
Compare
|
@gabotechs could you take a look at this change? It's a big diff but over half of it is generated code. I've tried to stack the commits to make it as reviewable as possible. |
|
Being realistic I don't think I can afford to review this any time soon, please don't feel forced to wait for me specifically to ship this, and thanks so much for working on it 🙏 If nobody gets to this hopefully I can free up the backlog in a few weeks. |
|
Marked as draft after 14 days without activity: merge conflicts. Please address these items and mark Ready for review when ready. |
|
@alamb this is the PR I mentioned that I think is mostly mechanical but large because of churn and generated code. Do you think you could take a look? |
009fa28 to
95d423e
Compare
95d423e to
08b0a01
Compare
Adds data_source = 42 and data_sink = 43 to PhysicalPlanNode, with
DataSourceNode, FileSourceNode and DataSinkNode oneofs that each have an
extension {name, payload} arm. Schema only; the next commit regenerates
the Rust code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mechanical: output of datafusion/proto-models/regen.sh, no manual edits. datafusion-proto does not build at this commit: its matches handle the new variants in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New hooks return only their own message: DataSource::try_to_proto_source, FileSource::try_to_proto_file_source and DataSink::try_to_proto_sink. Built-ins implement only these, and datafusion-proto always writes the layered form. The 55 hooks and the whole-plan decode helpers are deprecated and otherwise unchanged. The deprecated flat variants still decode: each is mapped to the layered decoders, with format fields converted by the From impls in datafusion-proto-models/src/physical_plan_compat.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
08b0a01 to
3648d81
Compare
|
@alamb I've rebased this PR. I split out code generation into it's own commit (it's 2.7k LOC out of the 4k LOC). Proto changes are ~120LOC, the code changes are ~800LOC. The rest is tests, upgrade guide. |
Checking |
|
I found this PR description really hard to read / understand the rationale for as it was talking about a bunch of code details that I am unfamiliar with rather than what the purpose is in terms of end user terms. I had my agent do some analysis, and I think the actual usecase is something like Who is this for:People who ship physical plans between processes (e.g. distributed engines built on Concrete usecase:A distributed engine that scans a "custom" file format (that is not part of the DataFusion core), for example TodayVortexSource has one piece of its own state (say, a pushed-down predicate), but its hook must produce the whole plan node, including everything impl FileSource for VortexSource {
fn try_to_proto(&self, base: &FileScanConfig, ctx: &ExecutionPlanEncodeCtx<'_>)
-> Result<Option<PhysicalPlanNode>>
{
// Must carry the shared config (files, projection, stats, 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 After this PR and the follow-upsThe source describes only itself: 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
})),
}))
}
}Is that accurate? |
alamb
left a comment
There was a problem hiding this comment.
Thank you for this PR @adriangb
Breaking up the PR into commits helped me review it for sure (the generated code specially is large)
I went through this and it seems like a good idea to me. I left some comments, but nothing required. However, I do think it is worth seriously considering maintaining backwards compatibility shims (as that is part of what ballooned this PR in the first place
Before merging, I request
- A ticket explaining the feature from an end user perspective (maybe it is #26824 (comment), but I am not sure)
Also as part of this project (as another PR), I would like to request an example (or a modified existing example) in datafusion-examples showing how this PR would be used -- e.g. implement a custom data source and show how to deserialize it, etc
| /// | ||
| /// Payloads without a mode default to newline-delimited JSON, and payloads without | ||
| /// `coerce_primitive` default to `false`. | ||
| pub fn try_from_proto_file_source( |
| /// [`Self::try_to_proto`] hook and then to the extension codec. | ||
| /// * `Ok(Some(node))` — fully serialized. | ||
| /// | ||
| /// [`DataSinkNode`]: datafusion_proto_models::protobuf::DataSinkNode |
There was a problem hiding this comment.
How would a custom DataSource extend the datafusion_proto_models::protobuf::DataSinkNode ? Wouldn't it have to know its own serialzation?
There was a problem hiding this comment.
I see - the idea is to use the extension location:
message DataSinkNode {
oneof sink_type {
JsonSink json = 1;
CsvSink csv = 2;
ParquetSink parquet = 3;
ExtensionDataSinkNode extension = 15; // the only arm a custom sink can use
}
}
message ExtensionDataSinkNode {
string name = 1; // which sink type this is
bytes payload = 2; // opaque to DataFusion
}| // SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership | ||
| // SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements | ||
|
|
||
| //! Conversions from the deprecated flat scan messages (`ParquetScanExecNode`, |
There was a problem hiding this comment.
what s this for? To try and maintain backwards compatibility?
There was a problem hiding this comment.
Given the stated compatibility goals:
datafusion/datafusion/proto/src/lib.rs
Lines 34 to 38 in 3648d81
It seems to me like trying to maintain some sort of "datafusion 57 can decode datafusion 56 created plans" is not worth the extra code / complexity (though maybe these days with AI agents it can work)
I would instead suggest we make the old (deprecated) methods return an error / fail fast (or maybe even remove them entirely to cause a compiler error). While that will cause more direct pain on upgrade, I think that may be worth it in this case to keep the DataFusion code simpler
Also, with an appropriate upgrade guide and an example (see PR review) and agents actually doing the upgrade, the API changes may not be quite as bad as they once were.
| serialized by 57.0.0. Upgrade readers before (or together with) writers in | ||
| mixed-version deployments. | ||
|
|
||
| **Migration guide:** implement the new hook and return only your own message; |
There was a problem hiding this comment.
When ready, we should add a link here to the example of how to implement a custom data source serialization, deserialization

Which issue does this PR close?
ExecutionPlans to decode via a per-type registry instead ofPhysicalExtensionCodec#24631, feat: allow extensionPhysicalExprs to decode via a per-type registry #24628.Rationale for this change
The
DataSource,FileSourceandDataSinkproto hooks (added in 55.0.0) return a fullPhysicalPlanNode, which is the Exec wrapper. Decode in #26555 / #26807 works at the source level. So:extension_data_source_node); a source can return any plan variantFileSourceneeds a markerDataSourceThis PR adds a proto layer that mirrors the traits. Then #26555 / #26807 only add a decoder for the
extensionarms.Only the scan / sink variants of
PhysicalPlanNodeare shown. The otherExecutionPlanvariants (projection = 4,filter = 12, ...) do not change.Before:
After:
Timing: land before 57.0.0, together with #26555 / #26807. Then the hooks added in 55.0.0 change only once, through deprecation.
What changes are included in this PR?
decode_file_scan,build_data_sink), by reference, with no subtree copy. Format fields map throughFrom<&XScanExecNode> for XSourceNodeindatafusion-proto-models/src/physical_plan_compat.rs: one mapping per format, exhaustive destructure. The deprecatedXSource::try_from_protohelpers use the same impls.Ok(None))DataSource::try_to_proto_source → DataSourceNodeFileSource::try_to_proto_file_source → FileSourceNodeDataSink::try_to_proto_sink → DataSinkNodetry_to_protohooks added in 55.0.0, and the old public decode functions. They are otherwise unchanged: the hook defaults still returnNone, and built-ins implement only the new hooks.PhysicalExtensionCodecextensionarmsNo decoder for extension DataSource '{name}'. The registry is in #26555 / #26807.Suggested shape for #26555 after this PR:
What is the testing strategy for this PR?
datafusion/proto/tests/cases/plans/deprecated_data_source_proto_serialization.rs:built_ins_encode_layered_and_legacy_variants_decodemissing_fields_give_clear_errors,extension_nodes_without_decoder_errorExisting scan and sink tests in
sources.rs/sinks.rsnow read the layered form.Feature flags:
cargo check -p datafusion-protopasses with no default features,avro, default and all features.-p datafusion-datasourceand-p datafusionpass with no default features.cargo test -p datafusion-proto --no-default-featuresdoes not compile, onmaintoo: existing tests import Parquet types without a gate.Are there any user-facing changes?
try_to_protohooks (added in 55.0.0) onDataSource,FileSourceandDataSink. Existing implementations still work. Migration notes are inupgrading/57.0.0.md.Open points
#[deprecated]on a trait method gives no warning to implementers who override it.regen.shoutput, no need to review line by line), (3) hooks and encode/decode, (4) tests, (5) docs.datafusion-protodoes not build at commit 2 (non-exhaustive match on the new variants). This is OK for a squash merge.🤖 Generated with Claude Code