diff --git a/crates/deltalake-core/src/operations/convert_to_delta.rs b/crates/deltalake-core/src/operations/convert_to_delta.rs index 84fffa1578..53be090916 100644 --- a/crates/deltalake-core/src/operations/convert_to_delta.rs +++ b/crates/deltalake-core/src/operations/convert_to_delta.rs @@ -27,7 +27,7 @@ use serde_json::{Map, Value}; use std::{ collections::{HashMap, HashSet}, num::TryFromIntError, - str::Utf8Error, + str::{FromStr, Utf8Error}, sync::Arc, }; @@ -82,6 +82,21 @@ pub enum PartitionStrategy { Hive, } +impl FromStr for PartitionStrategy { + type Err = DeltaTableError; + + fn from_str(s: &str) -> DeltaResult { + 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, diff --git a/python/src/lib.rs b/python/src/lib.rs index 65c92ea197..4b58412fbb 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -1100,13 +1100,6 @@ fn save_mode_from_str(value: &str) -> PyResult { } } -fn partition_strategy_from_str(value: &str) -> PyResult { - 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 @@ -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); }