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

chore: make bson copy to options more consistent #2704

Merged
merged 3 commits into from
Feb 27, 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
8 changes: 6 additions & 2 deletions crates/protogen/src/metastore/types/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ pub enum CopyToFormatOptions {
Parquet(CopyToFormatOptionsParquet),
Lance(CopyToFormatOptionsLance),
Json(CopyToFormatOptionsJson),
Bson,
Bson(CopyToFormatOptionsBson),
}

impl Default for CopyToFormatOptions {
Expand All @@ -1738,7 +1738,7 @@ impl CopyToFormatOptions {
Self::Csv(_) => Self::CSV,
Self::Parquet(_) => Self::PARQUET,
Self::Json(_) => Self::JSON,
Self::Bson => Self::BSON,
Self::Bson(_) => Self::BSON,
Self::Lance(_) => Self::LANCE,
}
}
Expand All @@ -1760,6 +1760,10 @@ pub struct CopyToFormatOptionsJson {
pub array: bool,
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CopyToFormatOptionsBson {}


#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CopyToFormatOptionsLance {
pub max_rows_per_file: Option<usize>,
Expand Down
9 changes: 8 additions & 1 deletion crates/protogen/src/sqlexec/copy_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub enum CopyToFormatOptionsEnum {
Parquet(CopyToFormatOptionsParquet),
#[prost(message, tag = "4")]
Lance(CopyToFormatOptionsLance),
#[prost(message, tag = "5")]
Bson(CopyToFormatOptionsBson),
}

#[derive(Clone, PartialEq, Message)]
Expand Down Expand Up @@ -119,7 +121,7 @@ impl TryFrom<crate::metastore::types::options::CopyToFormatOptions> for CopyToFo
value: crate::metastore::types::options::CopyToFormatOptions,
) -> Result<Self, Self::Error> {
match value {
crate::metastore::types::options::CopyToFormatOptions::Bson => {
crate::metastore::types::options::CopyToFormatOptions::Bson(_) => {
Ok(CopyToFormatOptions::default())
}
crate::metastore::types::options::CopyToFormatOptions::Lance(opts) => {
Expand Down Expand Up @@ -198,6 +200,11 @@ impl TryFrom<CopyToFormatOptions> for crate::metastore::types::options::CopyToFo
crate::metastore::types::options::CopyToFormatOptionsJson { array: json.array },
))
}
CopyToFormatOptionsEnum::Bson(_) => {
Ok(crate::metastore::types::options::CopyToFormatOptions::Bson(
crate::metastore::types::options::CopyToFormatOptionsBson {},
))
}
CopyToFormatOptionsEnum::Parquet(parquet) => Ok(
crate::metastore::types::options::CopyToFormatOptions::Parquet(
crate::metastore::types::options::CopyToFormatOptionsParquet {
Expand Down
3 changes: 2 additions & 1 deletion crates/sqlexec/src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ mod test {
CopyToDestinationOptions,
CopyToDestinationOptionsLocal,
CopyToFormatOptions,
CopyToFormatOptionsBson,
};
use uuid::Uuid;

Expand Down Expand Up @@ -214,7 +215,7 @@ mod test {
dest: CopyToDestinationOptions::Local(CopyToDestinationOptionsLocal {
location: "/tmp".to_string(),
}),
format: CopyToFormatOptions::Bson,
format: CopyToFormatOptions::Bson(CopyToFormatOptionsBson {}),
}
.into_extension(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/sqlexec/src/planner/physical_plan/copy_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn get_sink_for_obj(
array: json_opts.array,
},
)),
CopyToFormatOptions::Bson => Box::new(BsonSink::from_obj_store(store, path)),
CopyToFormatOptions::Bson(_) => Box::new(BsonSink::from_obj_store(store, path)),
};
Ok(sink)
}
5 changes: 4 additions & 1 deletion crates/sqlexec/src/planner/session_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use protogen::metastore::types::options::{
CopyToDestinationOptionsLocal,
CopyToDestinationOptionsS3,
CopyToFormatOptions,
CopyToFormatOptionsBson,
CopyToFormatOptionsCsv,
CopyToFormatOptionsJson,
CopyToFormatOptionsLance,
Expand Down Expand Up @@ -1938,7 +1939,9 @@ impl<'a> SessionPlanner<'a> {
let array = m.remove_optional::<bool>("array")?.unwrap_or(false);
CopyToFormatOptions::Json(CopyToFormatOptionsJson { array })
}
Some(CopyToFormatOptions::BSON) => CopyToFormatOptions::Bson {},
Some(CopyToFormatOptions::BSON) => {
CopyToFormatOptions::Bson(CopyToFormatOptionsBson {})
}
Some(CopyToFormatOptions::LANCE) => {
CopyToFormatOptions::Lance(CopyToFormatOptionsLance {
max_rows_per_file: m.remove_optional("max_rows_per_file")?,
Expand Down
Loading