-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into merge-partitions
- Loading branch information
Showing
7 changed files
with
117 additions
and
3 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
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
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
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,48 @@ | ||
import pathlib | ||
|
||
import pyarrow as pa | ||
import pytest | ||
|
||
from deltalake import DeltaTable, write_deltalake | ||
from deltalake.exceptions import DeltaError, DeltaProtocolError | ||
|
||
|
||
def test_add_constraint(tmp_path: pathlib.Path, sample_table: pa.Table): | ||
write_deltalake(tmp_path, sample_table) | ||
|
||
dt = DeltaTable(tmp_path) | ||
|
||
dt.alter.add_constraint({"check_price": "price >= 0"}) | ||
|
||
last_action = dt.history(1)[0] | ||
assert last_action["operation"] == "ADD CONSTRAINT" | ||
assert dt.version() == 1 | ||
assert dt.metadata().configuration == { | ||
"delta.constraints.check_price": "price >= 0" | ||
} | ||
|
||
with pytest.raises(DeltaError): | ||
# Invalid constraint | ||
dt.alter.add_constraint({"check_price": "price < 0"}) | ||
|
||
with pytest.raises(DeltaProtocolError): | ||
data = pa.table( | ||
{ | ||
"id": pa.array(["1"]), | ||
"price": pa.array([-1], pa.int64()), | ||
"sold": pa.array(list(range(1)), pa.int32()), | ||
"deleted": pa.array([False] * 1), | ||
} | ||
) | ||
write_deltalake(tmp_path, data, engine="rust", mode="append") | ||
|
||
|
||
def test_add_multiple_constraints(tmp_path: pathlib.Path, sample_table: pa.Table): | ||
write_deltalake(tmp_path, sample_table) | ||
|
||
dt = DeltaTable(tmp_path) | ||
|
||
with pytest.raises(ValueError): | ||
dt.alter.add_constraint( | ||
{"check_price": "price >= 0", "check_price2": "price >= 0"} | ||
) |