-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 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
37 changes: 37 additions & 0 deletions
37
examples/docs_snippets/docs_snippets/concepts/assets/asset_checks/factory.py
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,37 @@ | ||
from typing import Any, List, Mapping | ||
|
||
from dagster import AssetCheckResult, Definitions, asset_check | ||
|
||
|
||
def make_checks(check_blobs: List[Mapping[str, Any]]): | ||
checks = [] | ||
for check_blob in check_blobs: | ||
|
||
@asset_check(name=check_blob["name"], asset=check_blob["asset"]) | ||
def _check(context): | ||
db_connection = ... | ||
rows = db_connection.execute(check_blob["sql"]) | ||
return AssetCheckResult( | ||
passed=len(rows) == 0, metadata={"num_rows": len(rows)} | ||
) | ||
|
||
checks.append(_check) | ||
|
||
return checks | ||
|
||
|
||
check_blobs = [ | ||
{ | ||
"name": "orders_id_has_no_nulls", | ||
"asset": "orders", | ||
"sql": "select * from orders where order_id is null", | ||
}, | ||
{ | ||
"name": "items_id_has_no_nulls", | ||
"asset": "items", | ||
"sql": "select * from items where item_id is null", | ||
}, | ||
..., | ||
] | ||
|
||
defs = Definitions(asset_checks=make_checks(check_blobs)) |