How to run these
Each check is a plain SELECT. Save it to a file and run it from whatever already runs jobs for you.
Cron and psql
# hourly; mails you when the query returns any rows (grep . exits 0 only when it sees output)
0 * * * * psql "$DATABASE_URL" -At -f freshness.sql | grep . && echo "freshness check failed" | mail -s "data check" [email protected]
dbt singular test
Save the zero rows version as tests/orders_freshness.sql. dbt fails the test when the query returns any row.
Airflow
Use the One number style with SQLValueCheckOperator. The operator fails the task when the query returns no rows, so the zero rows style would fail a healthy check. The count always returns one row, andpass_value=0 passes only when it is 0.
SQLValueCheckOperator(
task_id="orders_freshness",
conn_id="warehouse",
sql=FRESHNESS_SQL,
pass_value=0,
)
arcodash monitor
Paste the One number version as a query, save it, and add a monitor on the failing column with the condition above 0. The monitor runs on a schedule and posts to Slack or email when it trips.
Snowflake notes
Snowflake folds unquoted names to upper case. RAW.EVENTS and raw.events are the same table, so the generator leaves all-upper and all-lower names alone and quotes mixed case, which is the only form that matches a table created with quotes.
CURRENT_TIMESTAMP() follows the session TIMEZONE parameter, and TIMESTAMP_NTZ columns carry no zone. If your loader writes UTC into an NTZ column, set TIMEZONE to UTC for the monitoring user.
Snowflake also has QUALIFY, which makes duplicate detection shorter, but the generated GROUP BY form is portable and just as cheap on a key column.
Connecting Snowflake to arcodash is covered on the Snowflake connector page.