From 0b61692019a9504d8e3cbe051a47475a2b9a510b Mon Sep 17 00:00:00 2001 From: franz Date: Thu, 7 Mar 2024 00:25:40 +0100 Subject: [PATCH] release_gil --- python/src/lib.rs | 90 ++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/python/src/lib.rs b/python/src/lib.rs index 5963a42216..d2d39592ac 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -1401,60 +1401,62 @@ fn write_to_deltalake( writer_properties: Option>>, custom_metadata: Option>, ) -> PyResult<()> { - let batches = data.0.map(|batch| batch.unwrap()).collect::>(); - let save_mode = mode.parse().map_err(PythonError::from)?; + py.allow_threads(|| { + let batches = data.0.map(|batch| batch.unwrap()).collect::>(); + let save_mode = mode.parse().map_err(PythonError::from)?; - let options = storage_options.clone().unwrap_or_default(); - let table = rt()? - .block_on(DeltaOps::try_from_uri_with_storage_options( - &table_uri, options, - )) - .map_err(PythonError::from)?; + let options = storage_options.clone().unwrap_or_default(); + let table = rt()? + .block_on(DeltaOps::try_from_uri_with_storage_options( + &table_uri, options, + )) + .map_err(PythonError::from)?; - let mut builder = table - .write(batches) - .with_save_mode(save_mode) - .with_write_batch_size(max_rows_per_group as usize); - if let Some(schema_mode) = schema_mode { - builder = builder.with_schema_mode(schema_mode.parse().map_err(PythonError::from)?); - } - if let Some(partition_columns) = partition_by { - builder = builder.with_partition_columns(partition_columns); - } + let mut builder = table + .write(batches) + .with_save_mode(save_mode) + .with_write_batch_size(max_rows_per_group as usize); + if let Some(schema_mode) = schema_mode { + builder = builder.with_schema_mode(schema_mode.parse().map_err(PythonError::from)?); + } + if let Some(partition_columns) = partition_by { + builder = builder.with_partition_columns(partition_columns); + } - if let Some(writer_props) = writer_properties { - builder = builder.with_writer_properties( - set_writer_properties(writer_props).map_err(PythonError::from)?, - ); - } + if let Some(writer_props) = writer_properties { + builder = builder.with_writer_properties( + set_writer_properties(writer_props).map_err(PythonError::from)?, + ); + } - if let Some(name) = &name { - builder = builder.with_table_name(name); - }; + if let Some(name) = &name { + builder = builder.with_table_name(name); + }; - if let Some(description) = &description { - builder = builder.with_description(description); - }; + if let Some(description) = &description { + builder = builder.with_description(description); + }; - if let Some(predicate) = predicate { - builder = builder.with_replace_where(predicate); - }; + if let Some(predicate) = predicate { + builder = builder.with_replace_where(predicate); + }; - if let Some(config) = configuration { - builder = builder.with_configuration(config); - }; + if let Some(config) = configuration { + builder = builder.with_configuration(config); + }; - if let Some(metadata) = custom_metadata { - let json_metadata: Map = - metadata.into_iter().map(|(k, v)| (k, v.into())).collect(); - builder = builder.with_metadata(json_metadata); - }; + if let Some(metadata) = custom_metadata { + let json_metadata: Map = + metadata.into_iter().map(|(k, v)| (k, v.into())).collect(); + builder = builder.with_metadata(json_metadata); + }; - rt()? - .block_on(builder.into_future()) - .map_err(PythonError::from)?; + rt()? + .block_on(builder.into_future()) + .map_err(PythonError::from)?; - Ok(()) + Ok(()) + }) } #[pyfunction]