-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
fdabd1a
commit d42d881
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pathlib | ||
|
||
import pyarrow as pa | ||
import pyarrow.compute as pc | ||
|
||
from deltalake.table import DeltaTable | ||
from deltalake.writer import write_deltalake | ||
|
||
|
||
def test_delete_no_predicates(existing_table: DeltaTable): | ||
old_version = existing_table.version() | ||
|
||
existing_table.delete() | ||
|
||
last_action = existing_table.history(1)[0] | ||
assert last_action["operation"] == "DELETE" | ||
assert existing_table.version() == old_version + 1 | ||
|
||
dataset = existing_table.to_pyarrow_dataset() | ||
assert dataset.count_rows() == 0 | ||
|
||
|
||
def test_delete_a_partition(tmp_path: pathlib.Path, sample_data: pa.Table): | ||
write_deltalake(tmp_path, sample_data, partition_by=["bool"]) | ||
|
||
dt = DeltaTable(tmp_path) | ||
old_version = dt.version() | ||
|
||
expr = pc.field("bool") != pc.scalar(True) | ||
expected_table = sample_data.filter(expr) | ||
|
||
dt.delete(predicate="bool = true") | ||
|
||
last_action = dt.history(1)[0] | ||
assert last_action["operation"] == "DELETE" | ||
assert dt.version() == old_version + 1 | ||
|
||
table = dt.to_pyarrow_table() | ||
assert table.equals(expected_table) | ||
assert len(dt.files()) == 1 | ||
|
||
|
||
def test_delete_some_rows(existing_table: DeltaTable): | ||
old_version = existing_table.version() | ||
|
||
expr = ~pc.field("utf8").isin(["0", "1"]) | ||
expected_table = existing_table.to_pyarrow_table().filter(expr) | ||
|
||
existing_table.delete(predicate="utf8 in ('0', '1')") | ||
|
||
last_action = existing_table.history(1)[0] | ||
assert last_action["operation"] == "DELETE" | ||
assert existing_table.version() == old_version + 1 | ||
|
||
table = existing_table.to_pyarrow_table() | ||
assert table.equals(expected_table) |