Checklist (run after each ETL load):1) Row count / load success- Purpose: detect missing/partial loads.- SQL:sql
SELECT COUNT(*) AS rows_loaded FROM sales_staging WHERE load_date = CURRENT_DATE;
Compare to yesterday or expected count; alert if < threshold (e.g., < 95% of expected or diff > X%).2) Delta count / freshness- Purpose: ensure new data arrived.- SQL:sql
SELECT MAX(sale_timestamp) AS latest_ts FROM sales_fact;
Alert if latest_ts < (CURRENT_TIMESTAMP - INTERVAL '24 hours').3) Null ratio on key fields- Purpose: critical fields must be populated.- SQL:sql
SELECT
SUM(CASE WHEN customer_id IS NULL THEN 1 ELSE 0 END) * 1.0 / COUNT(*) AS pct_null_customer
FROM sales_fact
WHERE load_date = CURRENT_DATE;
Alert if pct_null_customer > 0.01 (tunable).4) Referential integrity (lookup keys)- Purpose: detect orphaned foreign keys.- SQL:sql
SELECT COUNT(*) AS orphan_count
FROM sales_fact f
LEFT JOIN customers c ON f.customer_id = c.customer_id
WHERE f.load_date = CURRENT_DATE AND c.customer_id IS NULL;
Alert if orphan_count > 0.5) Aggregate sanity checks- Purpose: catch major value shifts.- SQL:sql
SELECT SUM(amount) AS total_sales, COUNT(*) AS txns FROM sales_fact WHERE load_date = CURRENT_DATE;
Compare to moving average (7-day); alert if outside nσ threshold.6) Duplicate detection- Purpose: prevent double-counting.- SQL:sql
SELECT sale_id, COUNT(*) FROM sales_fact WHERE load_date = CURRENT_DATE GROUP BY sale_id HAVING COUNT(*) > 1;
7) Schema / row-level validation- Purpose: verify types/ranges.- Example: check negative amounts:sql
SELECT COUNT(*) FROM sales_fact WHERE amount < 0 AND load_date = CURRENT_DATE;
Notification & workflow:- Automate checks via scheduler (Airflow/cron) that runs SQL and captures results.- On failure: create alert with context (failed check, query result, sample rows) sent to: - PagerDuty/Slack channel #data-alerts for on-call BI/ETL engineer - Email to data owners and dashboard stakeholders with remediation steps and link to runbook- Include automatic ticket creation (Jira) if failure persists >1 run.- Provide dashboards showing check history and MTTR metrics so stakeholders see reliability trends.Thresholds, sample sizes and alerting severity should be tuned with stakeholders to avoid noise.