Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add usage guide for check constraints #2079

Merged
merged 8 commits into from
Jan 16, 2024
Prev Previous commit
Next Next commit
docs: add usage guide for check constraints
  • Loading branch information
hntd187 committed Jan 15, 2024
commit 84bd9f515a519c6a6aaab74a71dcbb5737fc6592
6 changes: 4 additions & 2 deletions docs/src/python/check_constraints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
def add_constraint():
# --8<-- [start:add_constraint]
from deltalake import DeltaTable

dt = DeltaTable("../rust/tests/data/simple_table")

# Check the schema before hand
Expand All @@ -9,12 +10,13 @@ def add_constraint():
dt.alter.add_constraint({"id_gt_0": "id > 0"})
# --8<-- [end:add_constraint]


def add_data():
# --8<-- [start:add_data]
from deltalake import write_deltalake
import pandas as pd

df = pd.DataFrame({'id': [-1]})
write_deltalake(dt, df, mode='append', engine='rust')
df = pd.DataFrame({"id": [-1]})
write_deltalake(dt, df, mode="append", engine="rust")
# _internal.DeltaProtocolError: Invariant violations: ["Check or Invariant (id > 0) violated by value in row: [-1]"]
# --8<-- [end:add_data]