Skip to content

Commit ced1a14

Browse files
committed
Update to soda contracts v3
1 parent b6b3ff2 commit ced1a14

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

checks.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/usr/bin/env python
22

3-
from soda.contracts.connection import Connection, SodaException
4-
from soda.contracts.contract import Contract, ContractResult
3+
from soda.contracts.contract_verification import ContractVerification, ContractVerificationResult
54

6-
try:
7-
with Connection.from_yaml_file("./connection.yml") as connection:
8-
contract: Contract = Contract.from_yaml_file("./customers.contract.yml")
9-
contract_result: ContractResult = contract.verify(connection)
10-
11-
print("Soda checks passed")
12-
except SodaException as e:
13-
print(e.contract_result)
5+
contract_verification_result: ContractVerificationResult = (
6+
ContractVerification.builder()
7+
.with_contract_yaml_file('./customers.contract.yml')
8+
.with_warehouse_yaml_file('./connection.yml')
9+
.execute()
10+
.assert_ok()
11+
)

connection.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
type: postgres
2-
host: localhost
3-
database: postgres
4-
username: postgres
5-
password: secret
1+
name: local_postgres
2+
type: postgres
3+
connection:
4+
host: localhost
5+
database: postgres
6+
username: postgres
7+
password: secret

customers.contract.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
dataset: customers
2-
owner: product-team@data-contracts.com
2+
owner:
3+
email: product-team@data-contracts.com
34
description: All active customers of our product.
45
version: 1
56

@@ -23,3 +24,9 @@ columns:
2324
- name: distance
2425
description: The distance the customer is from our shop
2526
data_type: INTEGER
27+
28+
checks:
29+
- type: metric_expression
30+
metric: retention_period
31+
expression_sql: COUNT(CASE WHEN created < NOW() - interval '1 year' THEN 1 END)
32+
must_be: 0

lib/data_contract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def to_datacontract_cli(contract):
4040
title = contract["dataset"],
4141
version = str(contract["version"]),
4242
description = contract["description"],
43-
owner = contract["owner"],
43+
owner = contract["owner"]["email"],
4444
),
4545
servers = dict(
4646
workshop = dict(

main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
from data_contract import *
77

88
import yaml
9-
from soda.contracts.contract import Contract
109

1110
with open("./customers.contract.yml", "r") as stream:
1211
contents = stream.read()
1312
contract = yaml.safe_load(contents)
14-
soda_contract = Contract.from_yaml_str(contents)
1513

1614
print(
1715
f'Successfully parsed the `{contract["dataset"]}` contract, which is owned by `{contract["owner"]}`.')

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pyyaml==6.0
2-
soda-core==3.3.2
3-
soda-core-contracts==3.3.2
4-
soda-core-postgres==3.3.2
2+
soda-core==3.3.5
3+
soda-core-contracts==3.3.5
4+
soda-core-postgres==3.3.5

0 commit comments

Comments
 (0)