Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize CompressionTypeVariant encoding in protobuf #8785

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ message CreateExternalTableNode {
bool if_not_exists = 7;
string delimiter = 8;
string definition = 9;
string file_compression_type = 10;
reserved 10; // was string file_compression_type
CompressionTypeVariant file_compression_type = 17;
repeated LogicalExprNodeCollection order_exprs = 13;
bool unbounded = 14;
map<string, string> options = 11;
Expand Down
10 changes: 6 additions & 4 deletions datafusion/proto/src/generated/pbjson.rs

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

4 changes: 2 additions & 2 deletions datafusion/proto/src/generated/prost.rs

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

17 changes: 15 additions & 2 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,16 @@ impl AsLogicalPlan for LogicalPlanNode {
column_defaults.insert(col_name.clone(), expr);
}

let file_compression_type = protobuf::CompressionTypeVariant::try_from(
create_extern_table.file_compression_type,
)
.map_err(|_| {
proto_error(format!(
"Unknown file compression type {}",
create_extern_table.file_compression_type
))
})?;

Ok(LogicalPlan::Ddl(DdlStatement::CreateExternalTable(CreateExternalTable {
schema: pb_schema.try_into()?,
name: from_owned_table_reference(create_extern_table.name.as_ref(), "CreateExternalTable")?,
Expand All @@ -552,7 +562,7 @@ impl AsLogicalPlan for LogicalPlanNode {
.clone(),
order_exprs,
if_not_exists: create_extern_table.if_not_exists,
file_compression_type: CompressionTypeVariant::from_str(&create_extern_table.file_compression_type).map_err(|_| DataFusionError::NotImplemented(format!("Unsupported file compression type {}", create_extern_table.file_compression_type)))?,
file_compression_type: file_compression_type.into(),
definition,
unbounded: create_extern_table.unbounded,
options: create_extern_table.options.clone(),
Expand Down Expand Up @@ -1410,6 +1420,9 @@ impl AsLogicalPlan for LogicalPlanNode {
converted_column_defaults.insert(col_name.clone(), expr.try_into()?);
}

let file_compression_type =
protobuf::CompressionTypeVariant::from(file_compression_type);

Ok(protobuf::LogicalPlanNode {
logical_plan_type: Some(LogicalPlanType::CreateExternalTable(
protobuf::CreateExternalTableNode {
Expand All @@ -1423,7 +1436,7 @@ impl AsLogicalPlan for LogicalPlanNode {
delimiter: String::from(*delimiter),
order_exprs: converted_order_exprs,
definition: definition.clone().unwrap_or_default(),
file_compression_type: file_compression_type.to_string(),
file_compression_type: file_compression_type.into(),
unbounded: *unbounded,
options: options.clone(),
constraints: Some(constraints.clone().into()),
Expand Down
12 changes: 12 additions & 0 deletions datafusion/proto/src/physical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,18 @@ impl From<protobuf::CompressionTypeVariant> for CompressionTypeVariant {
}
}

impl From<CompressionTypeVariant> for protobuf::CompressionTypeVariant {
fn from(value: CompressionTypeVariant) -> Self {
match value {
CompressionTypeVariant::GZIP => Self::Gzip,
CompressionTypeVariant::BZIP2 => Self::Bzip2,
CompressionTypeVariant::XZ => Self::Xz,
CompressionTypeVariant::ZSTD => Self::Zstd,
CompressionTypeVariant::UNCOMPRESSED => Self::Uncompressed,
}
}
}

impl TryFrom<&protobuf::FileTypeWriterOptions> for FileTypeWriterOptions {
type Error = DataFusionError;

Expand Down