Data-quality tests every warehouse needs (2026 playbook)
Six test categories that catch 90% of the production data-quality issues that hit revenue metrics. Written as a checklist, not a manifesto.
The dashboard was fine on Friday. On Monday it shows revenue down 34% week over week, the CFO has already screenshotted it, and it is 08:47. Somebody in the ETL chain shipped a change on Sunday night that duplicated every orders row exactly twice, but the dashboard just renders SUM(amount) and does not know the difference. You do. Now.
The whole point of data-quality tests is to be the person who found out at 03:00, not 08:47. What people disagree on is which tests actually earn their keep, and the answer is boring: a small number of categories catch almost all of the issues, and everything else is worth writing only when it has already burned you once. This is that shortlist, written as a checklist you can walk down on a Monday morning instead of a manifesto about the six pillars of data reliability. Six categories. Cover them on your revenue-impacting models and you will catch the vast majority of the issues that make it to the CFO’s screenshot. The dbt team has a good piece on what data quality even means as a term, and I broadly agree that quality is fitness for a purpose rather than an absolute score. Six categories is not the six commandments; it is the shape of what tends to break in a warehouse, sorted by how often the breakage hits a revenue metric.
Category 1: uniqueness
The single most common production incident in a warehouse is a primary key that stops being unique. It is almost always upstream: a soft-delete replay, a CDC stream that reconnected and replayed part of its buffer, a manual backfill run twice, an incremental model’s unique_key misconfigured. The symptom is always the same. SUM(amount) doubles. Nobody notices for a day because individual rows still look right.
Every fact and dimension table gets a uniqueness test on its natural key. Every one.
# schema.yml
models:
- name: fct_orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: dim_customers
columns:
- name: customer_id
tests:
- unique
- not_null
If you are not on dbt, the same test in raw SQL is trivial and easier to reason about than most people admit:
SELECT order_id, count() AS n
FROM fct_orders
GROUP BY order_id
HAVING n > 1
LIMIT 100;
Zero rows is a pass. Any row is an incident. Wire it to alerting so the first to notice is a Slack channel, not the CFO. Full reference for unique, not_null, accepted_values, and relationships lives in the dbt tests documentation - worth reading once end-to-end.
Composite keys are the one nuance. If your fact table’s grain is (order_id, line_item_id), the uniqueness test needs the tuple, not either column alone. dbt has dbt_utils.unique_combination_of_columns for this. Do not skip it - the day order_id alone stops being unique, that assumption is the bug.
Category 2: non-null on required columns
Nulls in a numeric aggregation are the second most common way a dashboard silently lies. SUM ignores nulls, COUNT(*) does not, COUNT(col) does, AVG skips them, and none of those behaviours matches what a business user assumes when they say “average deal size”. If amount is null on 12% of rows because a new payment method landed upstream and the ETL never mapped its total column, the dashboard renders a smaller-than-real average and nobody knows.
Put not_null on every column a downstream metric depends on. Foreign keys, timestamps, amounts, statuses, everything that appears in a WHERE, GROUP BY, or SUM. If a column is legitimately nullable, say so with a comment and move on. Test the columns that must not be null.
- name: fct_orders
columns:
- name: customer_id
tests: [not_null]
- name: created_at
tests: [not_null]
- name: amount_usd
tests: [not_null]
- name: status
tests: [not_null]
A test that finds nulls is rarely a “data quality problem” - it is usually an upstream schema change nobody told the analytics team about. The test is a smoke alarm, not a diagnosis.
Category 3: referential integrity
Foreign keys in analytical warehouses are not enforced by the engine. ClickHouse does not have them at all. Snowflake and BigQuery let you declare them as metadata but never check them. So the day an orders.customer_id points at a customer_id that does not exist in dim_customers, the inner join silently drops the row (or the left join emits nulls), and the revenue attached to that order vanishes from every customer-level rollup.
For every fact-to-dimension join your marts actually rely on, write a relationships test:
- name: fct_orders
columns:
- name: customer_id
tests:
- relationships:
to: ref('dim_customers')
field: customer_id
The raw-SQL version is a left join back to the dimension and count of unmatched rows:
SELECT count() AS orphan_orders
FROM fct_orders f
LEFT JOIN dim_customers c ON f.customer_id = c.customer_id
WHERE c.customer_id IS NULL;
Where this test gets abused is on high-cardinality tables where “one orphan per week is fine, ten thousand is not.” Do not treat referential integrity as pass/fail there. Treat it as a threshold and alert on the delta from a rolling baseline - which is really a distribution test, category 6.
Category 4: freshness (source SLA)
Every dashboard implicitly claims a freshness SLA. The exec dashboard is expected to be current as of last night. The ops dashboard is expected to be current as of five minutes ago. Nobody writes these expectations down, and nobody notices when the ETL silently paused at 02:00 on a Sunday because the source database rolled a credential.
Freshness tests check that the newest row in a table is more recent than X, and they run per source. dbt’s sources.yml supports it directly:
sources:
- name: raw_stripe
tables:
- name: charges
loaded_at_field: created_at
freshness:
warn_after: {count: 6, period: hour}
error_after: {count: 24, period: hour}
In raw SQL, one of these per critical source table:
SELECT
max(created_at) AS latest_row,
now() - max(created_at) AS staleness
FROM raw_stripe.charges;
Watch the source landing table, not the mart. A fresh source with a stale mart is an orchestration bug the scheduler already knows about. A source that is 27 hours old is an ELT failure the scheduler did not surface - the interesting case. Soda does this well as a standalone tool if you want freshness decoupled from your transformation layer.
Category 5: accepted values (enum-like columns)
Every warehouse has string columns that are supposed to be one of a small set: order_status IN ('pending','paid','refunded','failed'), country_code in the ISO-3166 set, plan_tier in ('free','pro','enterprise'). And every warehouse eventually has a plan_tier row that says Pro (capital P) because a new sign-up flow bypassed the normalization, and now the plan_tier = 'pro' filter on the exec dashboard is missing 8% of paying customers.
The accepted-values test is boring and every project needs a dozen of them:
- name: dim_customers
columns:
- name: plan_tier
tests:
- accepted_values:
values: ['free', 'pro', 'enterprise']
- name: country_code
tests:
- accepted_values:
values: ['US', 'GB', 'DE', 'FR', 'LT', 'PL', 'ES', 'IT'] # etc.
quote: true
In ClickHouse, the raw check uses notIn:
SELECT plan_tier, count() AS n
FROM dim_customers
WHERE plan_tier NOT IN ('free', 'pro', 'enterprise')
GROUP BY plan_tier;
Two subtleties. First, case sensitivity: run lower(plan_tier) against the accepted list so a Pro value fires the test instead of slipping through. Second, this test is how you catch schema drift in the source. If plan_tier starts returning pro_annual because product shipped a new SKU, you want the test to fire, not for the analyst to notice three weeks later.
Category 6: distribution (row-count deltas and statistical outliers)
The first five categories are pass/fail. This one is not, and it is the category that catches the incidents the first five miss. If yesterday’s fct_orders had 12,400 rows and today’s has 24,800, none of the categories above will fire - every row is unique, no nulls, all foreign keys resolve, the source is fresh, every status is a known value. But the number is wrong and revenue looks like it doubled.
Distribution tests fall into three shapes and every warehouse needs some of each.
Row-count deltas. Compare today’s row count against a rolling baseline (7-day or 28-day). Alert when the delta is outside a threshold. The concrete implementation depends on your warehouse but in ClickHouse the window functions and array functions make it a two-line check:
WITH daily AS (
SELECT toDate(created_at) AS d, count() AS n
FROM fct_orders
WHERE created_at > now() - INTERVAL 30 DAY
GROUP BY d
)
SELECT
d,
n,
avg(n) OVER (ORDER BY d ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING) AS baseline,
n / nullIf(avg(n) OVER (ORDER BY d ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING), 0) AS ratio
FROM daily
ORDER BY d DESC
LIMIT 1;
Alert if ratio is outside [0.5, 2.0] for high-volume tables, or a wider window for spikier ones. You will tune this. That is fine.
Column-value distributions. For columns that drive revenue metrics, check that today’s value distribution looks like last week’s. A shift in the ratio of paid to pending in order_status is often the first signal that a webhook is dropping updates.
Statistical outliers. For continuous columns like amount_usd, watch max/min/p99. A single order at 9,999,999.00 is either a whale or a data-entry accident - know which today, not when the whale shows up in a churn cohort. The Great Expectations expectation gallery is a good reference for what these look like across libraries.
Distribution tests are where cost creeps in. Do not run them on every table every hour. Run them on the tables feeding the dashboards on the CFO’s screen, at the cadence those dashboards refresh, and no more.
The false-positive problem
The reason data teams end up with a #data-alerts channel that everyone mutes is that most test suites are 40% real signal and 60% noise, and after two weeks of noise the on-call analyst stops looking. A test that fires every Sunday because the source is scheduled to be quiet is worse than no test at all - it teaches people to ignore the channel.
Three rules I hold to:
- Every test has an owner. Not a team. A person. If nobody knows whose job it is to look, it will be ignored. dbt lets you attach
meta: {owner: someone}and every alerting tool worth using can route on that field. - Every test has a severity.
warnanderrorare not the same.uniqueon a primary key iserror.distributionoutside a rolling baseline is usuallywarnuntil it fires three days in a row. Only page a human onerror. - Tests that fire without ever indicating a real problem get deleted. Not tuned. Not backlogged. Deleted. A test with a 100% false-positive rate is worse than no test. Log every fire, review monthly, cull.
The practical rule stays boring: the goal is not the most tests. It is a set of tests where every firing is worth a human’s time.
Where this ends up
Get the six categories written on the ten or fifteen models that feed your revenue metrics, be honest about pruning false positives, and you will catch the majority of incidents that used to hit the CFO first. That is the whole game. Everything past this - anomaly-detection ML, statistical process control, per-column entropy - is worth nothing if the uniqueness test on fct_orders.order_id is not already there and green.
The thing we built into Goni’s semantic layer is that these six categories are declarative on the model, not scattered across a separate testing DSL. unique, not_null, relationships, freshness, accepted_values, and distribution are all first-class YAML keys on the same model definition that renders on the dashboard, so the test result travels with the number - if a chart’s underlying test has failed in the last N hours, the chart tells you. That is the property that turns “we have a test suite” into “the user knows whether to trust the number they are looking at.” The tests are the checklist. Travelling with the number is what makes the checklist worth the effort.