diff --git a/python/deltalake/_internal.pyi b/python/deltalake/_internal.pyi index dc149642f3..497f828f2d 100644 --- a/python/deltalake/_internal.pyi +++ b/python/deltalake/_internal.pyi @@ -6,6 +6,7 @@ from typing import ( TYPE_CHECKING, Any, Literal, + Optional, Union, ) @@ -93,7 +94,10 @@ class RawDeltaTable: def get_add_file_sizes(self) -> dict[str, int]: ... def get_latest_version(self) -> int: ... def metadata(self) -> RawDeltaTableMetaData: ... - def protocol_versions(self) -> list[Any]: ... + def protocol_versions( + self, + ) -> tuple[int, int, Optional[list[str]], Optional[list[str]]]: ... + def table_config(self) -> tuple[bool, int]: ... def load_version(self, version: int) -> None: ... def load_with_datetime(self, ds: str) -> None: ... def files(self, partition_filters: PartitionFilterType | None) -> list[str]: ... diff --git a/python/deltalake/table.py b/python/deltalake/table.py index 973a472b3c..bac8d398ce 100644 --- a/python/deltalake/table.py +++ b/python/deltalake/table.py @@ -119,6 +119,11 @@ def __str__(self) -> str: ) +class DeltaTableConfig(NamedTuple): + without_files: bool + log_buffer_size: int + + class ProtocolVersions(NamedTuple): min_reader_version: int min_writer_version: int @@ -166,6 +171,10 @@ def __init__( log_buffer_size=log_buffer_size, ) + @property + def table_config(self) -> DeltaTableConfig: + return DeltaTableConfig(*self._table.table_config()) + @staticmethod def is_deltatable( table_uri: str, storage_options: dict[str, str] | None = None diff --git a/python/src/lib.rs b/python/src/lib.rs index c73a0ba5a6..cdca97c192 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -246,6 +246,14 @@ impl RawDeltaTable { self.with_table(|t| Ok(t.config.require_files)) } + pub fn table_config(&self) -> PyResult<(bool, usize)> { + self.with_table(|t| { + let config = t.config.clone(); + // Require_files inverted to reflect without_files + Ok((!config.require_files, config.log_buffer_size)) + }) + } + pub fn metadata(&self) -> PyResult { let metadata = self.with_table(|t| { t.metadata() diff --git a/python/tests/test_config.py b/python/tests/test_config.py new file mode 100644 index 0000000000..cb5a6ecce8 --- /dev/null +++ b/python/tests/test_config.py @@ -0,0 +1,28 @@ +from arro3.core import Table + +from deltalake import write_deltalake +from deltalake.table import DeltaTable, DeltaTableConfig + + +def test_config_roundtrip(tmp_path, sample_table: Table): + write_deltalake(tmp_path, sample_table) + + config = DeltaTableConfig(without_files=True, log_buffer_size=100) + + dt = DeltaTable( + tmp_path, + without_files=config.without_files, + log_buffer_size=config.log_buffer_size, + ) + + assert config == dt.table_config + + config = DeltaTableConfig(without_files=False, log_buffer_size=1) + + dt = DeltaTable( + tmp_path, + without_files=config.without_files, + log_buffer_size=config.log_buffer_size, + ) + + assert config == dt.table_config