Skip to content

proto: layered DataSource / FileSource / DataSink nodes (precursor to #26555, #26807) - #26824

Open
adriangb wants to merge 5 commits into
apache:mainfrom
adriangb:proto-datasource-node-layer
Open

adriangb wants to merge 5 commits into
apache:mainfrom
adriangb:proto-datasource-node-layer

Conversation

@adriangb

@adriangb adriangb commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

The DataSource, FileSource and DataSink proto hooks (added in 55.0.0) return a full PhysicalPlanNode, which is the Exec wrapper. Decode in #26555 / #26807 works at the source level. So:

Problem Result
A source must build its own wrapper Public helpers (extension_data_source_node); a source can return any plan variant
Built-in sources use their own plan variants Two ways to serialize a source (thread)
No file-source level A custom FileSource needs a marker DataSource
No source level on the wire An unregistered reader gives an unclear error, or decodes the wrong source

This PR adds a proto layer that mirrors the traits. Then #26555 / #26807 only add a decoder for the extension arms.

Only the scan / sink variants of PhysicalPlanNode are shown. The other ExecutionPlan variants (projection = 4, filter = 12, ...) do not change.

Before:

PhysicalPlanNode
├─ ...                 (other ExecutionPlan variants)
├─ parquet_scan = 1
├─ csv_scan     = 2
├─ avro_scan    = 17   (deprecated)
├─ json_scan    = 31   (deprecated)
├─ memory_scan  = 35   (deprecated)
├─ arrow_scan   = 38   (deprecated)
├─ json_sink    = 24   (deprecated)
├─ csv_sink     = 28   (deprecated)
└─ parquet_sink = 29   (deprecated)

After:

PhysicalPlanNode
├─ ...                 (other ExecutionPlan variants)
├─ parquet_scan = 1 ... parquet_sink = 29   (deprecated: decode only)
├─ data_source = 42: DataSourceExecNode
│  └─ DataSourceNode (oneof)
│     ├─ file: FileScanNode
│     │  ├─ base: FileScanExecConf
│     │  └─ FileSourceNode (oneof)
│     │     ├─ parquet / csv / json / avro / arrow
│     │     └─ extension {name, payload}
│     ├─ memory
│     └─ extension {name, payload}
└─ data_sink = 43: DataSinkExecNode {input, sort_order}
   └─ DataSinkNode (oneof)
      ├─ json / csv / parquet
      └─ extension {name, payload}

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?

Area Change
Proto New messages (see above). The new format messages keep the field tags of the legacy scan nodes, so the legacy → new translation only moves fields.
Encode Built-ins always write the new form.
Decode (legacy) Each deprecated variant decodes in one call through the new decoders (decode_file_scan, build_data_sink), by reference, with no subtree copy. Format fields map through From<&XScanExecNode> for XSourceNode in datafusion-proto-models/src/physical_plan_compat.rs: one mapping per format, exhaustive destructure. The deprecated XSource::try_from_proto helpers use the same impls.
New hooks (default Ok(None)) DataSource::try_to_proto_source → DataSourceNode
FileSource::try_to_proto_file_source → FileSourceNode
DataSink::try_to_proto_sink → DataSinkNode
Deprecated (not removed) The try_to_proto hooks added in 55.0.0, and the old public decode functions. They are otherwise unchanged: the hook defaults still return None, and built-ins implement only the new hooks.
Encode order new hook → deprecated hook → PhysicalExtensionCodec
extension arms Decode returns No decoder for extension DataSource '{name}'. The registry is in #26555 / #26807.

Suggested shape for #26555 after this PR:

pub trait ExtensionDataSourceFromProto: DataSource + Sized {
    const NAME: &'static str;
    fn try_from_proto(payload: &[u8], ctx: &ExecutionPlanDecodeCtx<'_>) -> Result<Arc<dyn DataSource>>;
    fn register_proto(registry: &mut ProtoDecoderRegistry) -> Result<()> { /* provided */ }
}

What is the testing strategy for this PR?

datafusion/proto/tests/cases/plans/deprecated_data_source_proto_serialization.rs:

Test Checks
built_ins_encode_layered_and_legacy_variants_decode Each built-in round-trips in the new form; its legacy variant decodes to the same plan and re-encodes byte-identical to the new form
missing_fields_give_clear_errors, extension_nodes_without_decoder_error Error text

Existing scan and sink tests in sources.rs / sinks.rs now read the layered form.

Feature flags: cargo check -p datafusion-proto passes with no default features, avro, default and all features. -p datafusion-datasource and -p datafusion pass with no default features. cargo test -p datafusion-proto --no-default-features does not compile, on main too: existing tests import Parquet types without a gate.

Are there any user-facing changes?

  • Deprecations: the try_to_proto hooks (added in 55.0.0) on DataSource, FileSource and DataSink. Existing implementations still work. Migration notes are in upgrading/57.0.0.md.
  • Wire: a 57.0.0 writer produces plans that a 56.x reader cannot decode. A 57.0.0 reader decodes 56.x plans. (Plans are not guaranteed compatible across versions.)

Open points

  • #[deprecated] on a trait method gives no warning to implementers who override it.
  • Commits: (1) proto messages, (2) generated code only (regen.sh output, no need to review line by line), (3) hooks and encode/decode, (4) tests, (5) docs. datafusion-proto does not build at commit 2 (non-exhaustive match on the new variants). This is OK for a squash merge.

🤖 Generated with Claude Code

@github-actions github-actions Bot added documentation Improvements or additions to documentation proto Related to proto crate datasource Changes to the datasource crate auto detected api change Auto detected API change labels Oct 27, 2026
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from 748f78a to 56a3c63 Compare October 27, 2026 20:18
@adriangb
adriangb requested a balanced review from Copilot October 27, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread datafusion/datasource/src/source.rs Resolved
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from a50ac0d to da361cb Compare October 27, 2026 23:10
@adriangb
adriangb marked this pull request as ready for review October 27, 2026 23:35
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from da361cb to 009fa28 Compare October 27, 2026 23:56
@adriangb

Copy link
Copy Markdown
Contributor Author

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

@gabotechs

Copy link
Copy Markdown
Contributor

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.

@github-actions
github-actions Bot marked this pull request as draft November 20, 2026 01:09
@github-actions

Copy link
Copy Markdown

Marked as draft after 14 days without activity: merge conflicts.

Please address these items and mark Ready for review when ready.

@adriangb

Copy link
Copy Markdown
Contributor Author

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

@alamb
alamb marked this pull request as ready for review November 20, 2026 14:54
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from 009fa28 to 95d423e Compare December 1, 2026 09:03
@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Dec 1, 2026
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from 95d423e to 08b0a01 Compare December 1, 2026 16:18
adriangb and others added 5 commits December 1, 2026 10:05
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>
@adriangb
adriangb force-pushed the proto-datasource-node-layer branch from 08b0a01 to 3648d81 Compare December 1, 2026 18:06
@adriangb

adriangb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

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

@alamb

alamb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@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

@alamb

alamb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

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 datafusion-proto) and who have their own source or sink types. Users of only the built-in Parquet/CSV/JSON/Avro/Arrow sources see no functional change.

Concrete usecase:

A distributed engine that scans a "custom" file format (that is not part of the DataFusion core), for example VortexSource implementing FileSource, and needs to send the scan from the coordinator to workers.

Today

VortexSource has one piece of its own state (say, a pushed-down predicate), but its hook must produce the whole plan node, including everything FileScanConfig owns:

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 PhysicalExtensionCodec has to recognize those bytes among every other extension plan, rebuild the FileScanConfig, and wrap it in a DataSourceExec.

After this PR and the follow-ups

The 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 alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need #[cfg(proto)] ?

/// [`Self::try_to_proto`] hook and then to the extension codec.
/// * `Ok(Some(node))` — fully serialized.
///
/// [`DataSinkNode`]: datafusion_proto_models::protobuf::DataSinkNode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would a custom DataSource extend the datafusion_proto_models::protobuf::DataSinkNode ? Wouldn't it have to know its own serialzation?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what s this for? To try and maintain backwards compatibility?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the stated compatibility goals:

//! # Version Compatibility
//!
//! The serialized form are not guaranteed to be compatible across
//! DataFusion versions. A plan serialized with one version of DataFusion
//! may not be able to deserialized with a different version.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ready, we should add a link here to the example of how to implement a custom data source serialization, deserialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate documentation Improvements or additions to documentation proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants