diff --git a/crates/deltalake-core/src/operations/write.rs b/crates/deltalake-core/src/operations/write.rs index f38b44fc69..440ca6dca0 100644 --- a/crates/deltalake-core/src/operations/write.rs +++ b/crates/deltalake-core/src/operations/write.rs @@ -111,6 +111,12 @@ pub struct WriteBuilder { writer_properties: Option, /// Additional metadata to be added to commit app_metadata: Option>, + /// Name of the table, only used when table doesn't exist yet + name: Option, + /// Description of the table, only used when table doesn't exist yet + description: Option, + /// Configurations of the delta table, only used when table doesn't exist + // configuration: Option>>, } impl WriteBuilder { @@ -131,6 +137,9 @@ impl WriteBuilder { overwrite_schema: false, writer_properties: None, app_metadata: None, + name: None, + description: None, + // configuration: None, } } @@ -214,6 +223,31 @@ impl WriteBuilder { self } + /// Specify the table name. Optionally qualified with + /// a database name [database_name.] table_name. + pub fn with_table_name(mut self, name: impl Into) -> Self { + self.name = Some(name.into()); + self + } + + /// Comment to describe the table. + pub fn with_description(mut self, description: impl Into) -> Self { + self.description = Some(description.into()); + self + } + + // /// Set configuration on created table + // pub fn with_configuration( + // mut self, + // configuration: impl IntoIterator, Option>)>, + // ) -> Self { + // self.configuration = configuration + // .into_iter() + // .map(|(k, v)| (k.into(), v.map(|s| s.into()))) + // .collect(); + // self + // } + async fn check_preconditions(&self) -> DeltaResult> { match self.log_store.is_delta_table_location().await? { true => { @@ -242,6 +276,19 @@ impl WriteBuilder { if let Some(partition_columns) = self.partition_columns.as_ref() { builder = builder.with_partition_columns(partition_columns.clone()) } + + if let Some(name) = self.name.as_ref() { + builder = builder.with_table_name(name.clone()); + }; + + if let Some(desc) = self.description.as_ref() { + builder = builder.with_comment(desc.clone()); + }; + + // if let Some(config) = self.configuration.as_ref() { + // builder = builder.with_configuration(config.clone()); + // }; + let (_, actions, _) = builder.into_table_and_actions()?; Ok(actions) } diff --git a/python/deltalake/_internal.pyi b/python/deltalake/_internal.pyi index 9605d61091..1989e39e8c 100644 --- a/python/deltalake/_internal.pyi +++ b/python/deltalake/_internal.pyi @@ -147,8 +147,8 @@ def write_to_deltalake( mode: str, max_rows_per_group: int, overwrite_schema: bool, - _name: Optional[str], - _description: Optional[str], + name: Optional[str], + description: Optional[str], _configuration: Optional[Mapping[str, Optional[str]]], storage_options: Optional[Dict[str, str]], ) -> None: ... diff --git a/python/deltalake/writer.py b/python/deltalake/writer.py index 15c7b1a5a7..35323f9a49 100644 --- a/python/deltalake/writer.py +++ b/python/deltalake/writer.py @@ -214,8 +214,8 @@ def write_deltalake( mode=mode, max_rows_per_group=max_rows_per_group, overwrite_schema=overwrite_schema, - _name=name, - _description=description, + name=name, + description=description, _configuration=configuration, storage_options=storage_options, ) diff --git a/python/src/lib.rs b/python/src/lib.rs index 8832a39d6c..c22fb408f0 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -1144,8 +1144,8 @@ fn write_to_deltalake( max_rows_per_group: i64, overwrite_schema: bool, partition_by: Option>, - _name: Option, - _description: Option, + name: Option, + description: Option, _configuration: Option>>, storage_options: Option>, ) -> PyResult<()> { @@ -1169,6 +1169,14 @@ fn write_to_deltalake( builder = builder.with_partition_columns(partition_columns); } + if let Some(name) = &name { + builder = builder.with_table_name(name); + }; + + if let Some(description) = &description { + builder = builder.with_description(description); + }; + rt()? .block_on(builder.into_future()) .map_err(PythonError::from)?; diff --git a/python/tests/test_writer.py b/python/tests/test_writer.py index 465a2b3e77..797b9365a9 100644 --- a/python/tests/test_writer.py +++ b/python/tests/test_writer.py @@ -189,8 +189,7 @@ def test_local_path( assert table == sample_data -@pytest.mark.skip(reason="Waiting on support with create matadata during write") -def test_roundtrip_metadata_rust(tmp_path: pathlib.Path, sample_data: pa.Table, engine): +def test_roundtrip_metadata_rust(tmp_path: pathlib.Path, sample_data: pa.Table): write_deltalake( tmp_path, sample_data, @@ -206,7 +205,7 @@ def test_roundtrip_metadata_rust(tmp_path: pathlib.Path, sample_data: pa.Table, assert metadata.name == "test_name" assert metadata.description == "test_desc" - assert metadata.configuration == {"delta.appendOnly": "false", "foo": "bar"} + # assert metadata.configuration == {"delta.appendOnly": "false", "foo": "bar"} def test_roundtrip_metadata(tmp_path: pathlib.Path, sample_data: pa.Table):