From af287f50e750770fb0cf32358222bdd809162451 Mon Sep 17 00:00:00 2001 From: Abdullahsab3 Date: Sat, 4 Jan 2025 15:46:07 +0100 Subject: [PATCH] docs: delete with the Rust API Signed-off-by: Abdullahsab3 --- .../deleting-rows-from-delta-lake-table.md | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/usage/deleting-rows-from-delta-lake-table.md b/docs/usage/deleting-rows-from-delta-lake-table.md index 6c852100e6..3fc2ec7a5b 100644 --- a/docs/usage/deleting-rows-from-delta-lake-table.md +++ b/docs/usage/deleting-rows-from-delta-lake-table.md @@ -17,11 +17,29 @@ Suppose you have the following Delta table with four rows: Here's how to delete all the rows where the `num` is greater than 2: -```python -dt = DeltaTable("tmp/my-table") -dt.delete("num > 2") -``` - +=== "Python" + + ```python + dt = DeltaTable("tmp/my-table") + dt.delete("num > 2") + ``` + +=== "Rust" + ```rust + let table = deltalake::open_table("./data/simple_table").await?; + let (table, delete_metrics) = DeltaOps(table) + .delete() + .with_predicate(col("num").gt(lit(2))) + .await?; + ``` + `with_predicate` expects an argument that can be translated to a Datafusion `Expression`. This can be either using the Dataframe API, or using a `SQL where` clause: + ```rust + let table = deltalake::open_table("./data/simple_table").await?; + let (table, delete_metrics) = DeltaOps(table) + .delete() + .with_predicate("num > 2") + .await?; + ``` Here are the contents of the Delta table after the delete operation has been performed: ```