Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ message CopyToNode {
repeated string partition_by = 7;
}

enum FileFormatKind {
FILE_FORMAT_KIND_UNSPECIFIED = 0;
FILE_FORMAT_KIND_CSV = 1;
FILE_FORMAT_KIND_JSON = 2;
FILE_FORMAT_KIND_PARQUET = 3;
FILE_FORMAT_KIND_ARROW = 4;
FILE_FORMAT_KIND_AVRO = 5;
}

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.

could we add some comments desribing what this message does

message FileFormatProto {
FileFormatKind kind = 1;
bytes options = 2;
Comment thread
Acfboy marked this conversation as resolved.
Outdated
}

message DmlNode{
enum Type {
UPDATE = 0;
Expand Down
197 changes: 197 additions & 0 deletions datafusion/proto/src/generated/pbjson.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions datafusion/proto/src/generated/prost.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
Acfboy marked this conversation as resolved.
Outdated
Comment thread
Acfboy marked this conversation as resolved.
Outdated

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;
Comment thread
Acfboy marked this conversation as resolved.
Outdated
Comment thread
Acfboy marked this conversation as resolved.
Outdated

let any = node.as_any();
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.

do we need to extract variable here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean we should inline node.as_any() instead of binding it to let any? I don't quite follow.

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.

yes, sorry for confusion

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thx for clarification!

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.

do we need to extract it as a variable here

let mut options = Vec::new();
Comment thread
Acfboy marked this conversation as resolved.
Outdated
Comment thread
Acfboy marked this conversation as resolved.
Outdated

let kind = if any.downcast_ref::<CsvFormatFactory>().is_some() {
file_formats::CsvLogicalExtensionCodec
.try_encode_file_format(&mut options, Arc::clone(&node))?;
protobuf::FileFormatKind::Csv
} else if any.downcast_ref::<JsonFormatFactory>().is_some() {
file_formats::JsonLogicalExtensionCodec
.try_encode_file_format(&mut options, Arc::clone(&node))?;
protobuf::FileFormatKind::Json
} else if any.downcast_ref::<ArrowFormatFactory>().is_some() {
file_formats::ArrowLogicalExtensionCodec
.try_encode_file_format(&mut options, Arc::clone(&node))?;
protobuf::FileFormatKind::Arrow
} else {
#[cfg(feature = "parquet")]
{
use datafusion_datasource_parquet::file_format::ParquetFormatFactory;
if any.downcast_ref::<ParquetFormatFactory>().is_some() {
file_formats::ParquetLogicalExtensionCodec
.try_encode_file_format(&mut options, Arc::clone(&node))?;
protobuf::FileFormatKind::Parquet
} else {
return not_impl_err!(
"Unsupported FileFormatFactory type for DefaultLogicalExtensionCodec"
);
}
}
#[cfg(not(feature = "parquet"))]
{
return not_impl_err!(
"Unsupported FileFormatFactory type for DefaultLogicalExtensionCodec"
);
}
};

let proto = protobuf::FileFormatProto {
kind: kind as i32,
options,
};
proto.encode(buf).map_err(|e| {
internal_datafusion_err!("Failed to encode FileFormatProto: {e}")
})?;
Ok(())
}
}

#[macro_export]
Expand Down
Loading