Acfboy commented on code in PR #20638:
URL: https://github.com/apache/datafusion/pull/20638#discussion_r2894113183


##########
datafusion/proto/src/logical_plan/mod.rs:
##########
@@ -207,6 +207,102 @@ impl LogicalExtensionCodec for 
DefaultLogicalExtensionCodec {
     ) -> Result<()> {
         not_impl_err!("LogicalExtensionCodec is not provided")
     }
+
+    fn try_decode_file_format(
+        &self,
+        buf: &[u8],
+        ctx: &TaskContext,
+    ) -> Result<Arc<dyn FileFormatFactory>> {
+        use prost::Message;
+
+        let proto = protobuf::FileFormatProto::decode(buf).map_err(|e| {
+            internal_datafusion_err!("Failed to decode FileFormatProto: {e}")
+        })?;
+
+        let kind = protobuf::FileFormatKind::try_from(proto.kind).map_err(|_| {
+            internal_datafusion_err!("Unknown FileFormatKind: {}", proto.kind)
+        })?;
+
+        match kind {
+            protobuf::FileFormatKind::Csv => 
file_formats::CsvLogicalExtensionCodec
+                .try_decode_file_format(&proto.options, ctx),
+            protobuf::FileFormatKind::Json => 
file_formats::JsonLogicalExtensionCodec
+                .try_decode_file_format(&proto.options, ctx),
+            #[cfg(feature = "parquet")]
+            protobuf::FileFormatKind::Parquet => {
+                file_formats::ParquetLogicalExtensionCodec
+                    .try_decode_file_format(&proto.options, ctx)
+            }
+            protobuf::FileFormatKind::Arrow => 
file_formats::ArrowLogicalExtensionCodec
+                .try_decode_file_format(&proto.options, ctx),
+            protobuf::FileFormatKind::Avro => 
file_formats::AvroLogicalExtensionCodec
+                .try_decode_file_format(&proto.options, ctx),
+            #[cfg(not(feature = "parquet"))]
+            protobuf::FileFormatKind::Parquet => {
+                not_impl_err!("Parquet support requires the 'parquet' feature")
+            }
+            protobuf::FileFormatKind::Unspecified => {
+                not_impl_err!("Unspecified file format kind")
+            }
+        }
+    }
+
+    fn try_encode_file_format(
+        &self,
+        buf: &mut Vec<u8>,
+        node: Arc<dyn FileFormatFactory>,
+    ) -> Result<()> {
+        use datafusion_datasource_arrow::file_format::ArrowFormatFactory;
+        use datafusion_datasource_csv::file_format::CsvFormatFactory;
+        use datafusion_datasource_json::file_format::JsonFormatFactory;
+        use prost::Message;

Review Comment:
   Sorry, it’s my bad habit carried over from python. I'll fix it.



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