Skip to content

Commit a1cd31d

Browse files
committed
feat: add lazy loading of tables
1 parent b3f478e commit a1cd31d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

python/deltalake/table.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def __init__(
229229
storage_options: Optional[Dict[str, str]] = None,
230230
without_files: bool = False,
231231
log_buffer_size: Optional[int] = None,
232+
lazy_load: bool = False
232233
):
233234
"""
234235
Create the Delta Table from a path with an optional version.
@@ -247,9 +248,19 @@ def __init__(
247248
This can decrease latency if there are many files in the log since the last checkpoint,
248249
but will also increase memory usage. Possible rate limits of the storage backend should
249250
also be considered for optimal performance. Defaults to 4 * number of cpus.
250-
251+
lazy_load: when true the table metadata isn't loaded
251252
"""
252253
self._storage_options = storage_options
254+
if lazy_load:
255+
self._table = RawDeltaTable.load_lazy(
256+
str(table_uri),
257+
version=version,
258+
storage_options=storage_options,
259+
without_files=without_files,
260+
log_buffer_size=log_buffer_size,
261+
)
262+
self._metadata = None
263+
return
253264
self._table = RawDeltaTable(
254265
str(table_uri),
255266
version=version,
@@ -425,6 +436,8 @@ def metadata(self) -> Metadata:
425436
Returns:
426437
the current Metadata registered in the transaction log
427438
"""
439+
if not self._metadata:
440+
self._metadata = Metadata(self._table)
428441
return self._metadata
429442

430443
def protocol(self) -> ProtocolVersions:

python/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ impl RawDeltaTable {
121121
})
122122
}
123123

124+
#[classmethod]
125+
fn load_lazy(_cls: &PyType, table_uri: &str) -> PyResult<Self> {
126+
let be = storage::get_backend_for_uri(table_uri).unwrap();
127+
let table = DeltaTable::new(table_uri, be, DeltaTableConfig::default())
128+
.map_err(PyDeltaTableError::from_raw)?;
129+
Ok(RawDeltaTable { _table: table })
130+
}
131+
124132
#[classmethod]
125133
#[pyo3(signature = (data_catalog, database_name, table_name, data_catalog_id, catalog_options = None))]
126134
fn get_table_uri_from_data_catalog(

0 commit comments

Comments
 (0)