Skip to content

Commit

Permalink
add FromStr
Browse files Browse the repository at this point in the history
  • Loading branch information
ion-elgreco committed Nov 19, 2023
1 parent 16e87a6 commit ec65587
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 16 additions & 1 deletion crates/deltalake-core/src/operations/convert_to_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serde_json::{Map, Value};
use std::{
collections::{HashMap, HashSet},
num::TryFromIntError,
str::Utf8Error,
str::{FromStr, Utf8Error},
sync::Arc,
};

Expand Down Expand Up @@ -82,6 +82,21 @@ pub enum PartitionStrategy {
Hive,
}

impl FromStr for PartitionStrategy {
type Err = DeltaTableError;

fn from_str(s: &str) -> DeltaResult<Self> {
let strategy = match s {
"hive" => Ok(PartitionStrategy::Hive),
_ => Err(DeltaTableError::Generic(format!(
"Invalid partition strategy provided {}",
s
))),
};
strategy
}
}

/// Build an operation to convert a Parquet table to a [`DeltaTable`] in place
pub struct ConvertToDeltaBuilder {
log_store: Option<LogStoreRef>,
Expand Down
9 changes: 1 addition & 8 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,13 +1100,6 @@ fn save_mode_from_str(value: &str) -> PyResult<SaveMode> {
}
}

fn partition_strategy_from_str(value: &str) -> PyResult<PartitionStrategy> {
match value {
"hive" => Ok(PartitionStrategy::Hive),
_ => Err(PyValueError::new_err("Invalid partition strategy provided")),
}
}

fn current_timestamp() -> i64 {
let start = SystemTime::now();
let since_the_epoch = start
Expand Down Expand Up @@ -1209,7 +1202,7 @@ fn convert_to_deltalake(
}

if let Some(partition_strategy) = &partition_strategy {
let strategy = partition_strategy_from_str(partition_strategy)?;
let strategy: PartitionStrategy = partition_strategy.parse().map_err(PythonError::from)?;
builder = builder.with_partition_strategy(strategy);
}

Expand Down

0 comments on commit ec65587

Please sign in to comment.