alamb commented on code in PR #26824:
URL: https://github.com/apache/datafusion/pull/26824#discussion_r4761910792


##########
datafusion/proto-models/src/physical_plan_compat.rs:
##########
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: Apache-2.0
+// 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`,

Review Comment:
   what s this for? To try and maintain backwards compatibility?



##########
datafusion/datasource/src/sink.rs:
##########
@@ -67,13 +67,30 @@ pub trait DataSink: Any + DisplayAs + Debug + Send + Sync {
     ///
     /// Returning `Ok(None)` lets the caller try its extension codec instead.
     #[cfg(feature = "proto")]
+    #[deprecated(since = "57.0.0", note = "implement `try_to_proto_sink` 
instead")]
     fn try_to_proto(
         &self,
         _exec: &DataSinkExec,
         _ctx: &datafusion_physical_plan::proto::ExecutionPlanEncodeCtx<'_>,
     ) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
         Ok(None)
     }
+
+    /// Serialize this sink into a [`DataSinkNode`], if it knows how.
+    /// [`DataSinkExec`] encodes its input and sort order alongside it.
+    ///
+    /// * `Ok(None)` (the default) — the caller falls back to the deprecated
+    ///   [`Self::try_to_proto`] hook and then to the extension codec.
+    /// * `Ok(Some(node))` — fully serialized.
+    ///
+    /// [`DataSinkNode`]: datafusion_proto_models::protobuf::DataSinkNode

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



##########
docs/source/library-user-guide/upgrading/57.0.0.md:
##########
@@ -391,3 +391,36 @@ simplify expressions such as `col IS NULL` on them.
 Row values are unchanged, but schema inspection can differ: code that compares
 the resulting schema against a hand-written one with `nullable: true` for
 every field needs to be updated.
+
+### Whole-plan `DataSource` / `FileSource` / `DataSink` proto hooks are 
deprecated
+
+Scans and sinks now serialize as layered `data_source` / `data_sink` plan
+nodes. Each level emits only its own message:
+
+| Deprecated                                                 | Replacement     
                                               |
+| ---------------------------------------------------------- | 
-------------------------------------------------------------- |
+| `DataSource::try_to_proto` → `PhysicalPlanNode`            | 
`DataSource::try_to_proto_source` → `DataSourceNode`           |
+| `FileSource::try_to_proto(base, ctx)` → `PhysicalPlanNode` | 
`FileSource::try_to_proto_file_source(ctx)` → `FileSourceNode` |
+| `DataSink::try_to_proto(exec, ctx)` → `PhysicalPlanNode`   | 
`DataSink::try_to_proto_sink(ctx)` → `DataSinkNode`            |
+| `{Csv,Json,Avro,Arrow,Parquet}Source::try_from_proto`      | 
`…Source::try_from_proto_file_source`                          |
+| `MemorySourceConfig::try_from_proto`                       | 
`MemorySourceConfig::try_from_proto_source`                    |
+| `{Csv,Json,Parquet}Sink::try_from_proto`                   | 
`TryFrom<&protobuf::{Csv,Json,Parquet}Sink>`                   |
+
+The deprecated hooks are still called when the new one returns `None`, so
+existing implementations keep working. The flat `parquet_scan`, `csv_scan`,
+`json_scan`, `avro_scan`, `arrow_scan`, `memory_scan`, `json_sink`,
+`csv_sink` and `parquet_sink` variants are no longer emitted but still decode.
+
+Plans encoded by 57.0.0 use the new `data_source` / `data_sink` variants, which
+older readers do not understand: a 56.x process cannot decode scans or sinks
+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;

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



##########
datafusion/proto-models/src/physical_plan_compat.rs:
##########
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: Apache-2.0
+// 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`,

Review Comment:
   Given the stated compatibility goals:
   
https://github.com/apache/datafusion/blob/3648d81e0f89bd516335860dd687a319b8f2d457/datafusion/proto/src/lib.rs#L34-L38
   
   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.



##########
datafusion/datasource-json/src/source.rs:
##########
@@ -328,30 +324,39 @@ impl JsonSource {
                 "PhysicalPlanNode is not a JsonScan"
             );
         };
-
-        // Exhaustive destructure: a new field on `JsonScanExecNode` is a
-        // compile error here rather than a silently ignored wire field.
-        let protobuf::JsonScanExecNode {
-            base_conf,
-            newline_delimited,
-            coerce_primitive,
-        } = scan;
-
-        let base_conf = base_conf.as_ref().ok_or_else(|| {
+        let base_conf = scan.base_conf.as_ref().ok_or_else(|| {
             datafusion_common::internal_datafusion_err!(
                 "JsonScanExecNode is missing required field 'base_conf'"
             )
         })?;
+        let source_node = protobuf::JsonSourceNode::from(scan);
+        let source = Self::try_from_proto_file_source(&source_node, base_conf, 
ctx)?;
+        let conf = FileScanConfig::try_from_proto(base_conf, ctx, source)?;
+        Ok(DataSourceExec::from_data_source(conf))
+    }
 
-        let table_schema = 
FileScanConfig::parse_table_schema_from_proto(base_conf)?;
-        let source = Arc::new(
+    /// Reconstructs a `JsonSource` from its protobuf representation. `base`
+    /// is the enclosing scan's shared config, used for the table schema.
+    ///
+    /// Payloads without a mode default to newline-delimited JSON, and 
payloads without
+    /// `coerce_primitive` default to `false`.
+    pub fn try_from_proto_file_source(

Review Comment:
   does it need `#[cfg(proto)]` ?



##########
datafusion/datasource/src/sink.rs:
##########
@@ -67,13 +67,30 @@ pub trait DataSink: Any + DisplayAs + Debug + Send + Sync {
     ///
     /// Returning `Ok(None)` lets the caller try its extension codec instead.
     #[cfg(feature = "proto")]
+    #[deprecated(since = "57.0.0", note = "implement `try_to_proto_sink` 
instead")]
     fn try_to_proto(
         &self,
         _exec: &DataSinkExec,
         _ctx: &datafusion_physical_plan::proto::ExecutionPlanEncodeCtx<'_>,
     ) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
         Ok(None)
     }
+
+    /// Serialize this sink into a [`DataSinkNode`], if it knows how.
+    /// [`DataSinkExec`] encodes its input and sort order alongside it.
+    ///
+    /// * `Ok(None)` (the default) — the caller falls back to the deprecated
+    ///   [`Self::try_to_proto`] hook and then to the extension codec.
+    /// * `Ok(Some(node))` — fully serialized.
+    ///
+    /// [`DataSinkNode`]: datafusion_proto_models::protobuf::DataSinkNode

Review Comment:
   I see - the idea is to use the extension location:
   
   ```proto
   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
   }
   ```



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