Skip to content

Commit

Permalink
expose update_incremental API to python binding (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
QP Hou authored Jul 20, 2021
1 parent 5ad31d0 commit 7be33d1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
31 changes: 6 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ link:https://github.com/rajasekarv/vega[vega], etc. It also provides bindings to

| Stream table update
| :heavy_check_mark:
|
| :heavy_check_mark:
|

| Filter files with partitions
Expand Down
4 changes: 2 additions & 2 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deltalake-python"
version = "0.5.1"
version = "0.5.2"
authors = ["Qingping Hou <[email protected]>"]
homepage = "https://github.com/delta-io/delta-rs"
license = "Apache-2.0"
Expand Down Expand Up @@ -45,7 +45,7 @@ requires-dist = [
'numpy<1.20.0;python_version<="3.6"',
'dataclasses;python_version<="3.6"',
'types-dataclasses;python_version<="3.6" and extra == "pandas"',
"pandas; extra == 'pandas'",
"pandas; extra == 'pandas' or extra == 'devel'",
"mypy; extra == 'devel'",
"isort; extra == 'devel'",
"pytest; extra == 'devel'",
Expand Down
7 changes: 7 additions & 0 deletions python/deltalake/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,10 @@ def to_pandas(
:return: a pandas dataframe
"""
return self.to_pyarrow_table(partitions, columns).to_pandas()

def update_incremental(self) -> None:
"""
Updates the DeltaTable to the latest version by incrementally applying
newer versions.
"""
self._table.update_incremental()
6 changes: 6 additions & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ impl RawDeltaTable {
)
.map_err(|_| PyDeltaTableError::new_err("Got invalid table schema"))
}

pub fn update_incremental(&mut self) -> PyResult<()> {
rt()?
.block_on(self._table.update_incremental())
.map_err(PyDeltaTableError::from_raw)
}
}

#[pyfunction]
Expand Down
8 changes: 8 additions & 0 deletions python/tests/test_table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def test_read_simple_table_by_version_to_dict():
assert dt.to_pyarrow_dataset().to_table().to_pydict() == {"value": [1, 2, 3]}


def test_read_simple_table_update_incremental():
table_path = "../rust/tests/data/simple_table"
dt = DeltaTable(table_path, version=0)
assert dt.to_pyarrow_dataset().to_table().to_pydict() == {"id": [0, 1, 2, 3, 4]}
dt.update_incremental()
assert dt.to_pyarrow_dataset().to_table().to_pydict() == {"id": [5, 7, 9]}


def test_read_partitioned_table_to_dict():
table_path = "../rust/tests/data/delta-0.8.0-partitioned"
dt = DeltaTable(table_path)
Expand Down
3 changes: 1 addition & 2 deletions rust/src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ impl DeltaTable {
Ok(())
}

/// Updates the DeltaTable to the most recent state committed to the transaction by
/// incrementally applying each version since current.
/// Updates the DeltaTable to the latest version by incrementally applying newer versions.
pub async fn update_incremental(&mut self) -> Result<(), DeltaTableError> {
self.version += 1;
self.apply_logs_from_current_version().await
Expand Down

0 comments on commit 7be33d1

Please sign in to comment.