What You'll Learn
- 1Describe the six data quality dimensions and map each one to a concrete SQL check
- 2Configure a Dataplex data scan with completeness, uniqueness, validity, and freshness rules
- 3Write Dataform assertions that fail the build before bad data reaches a dashboard
- 4Design a quarantine and alerting flow that keeps bad rows out of the curated layer
A pipeline that runs on time can still be wrong, and a dashboard that agrees with itself can still disagree with reality. Data quality work exists because the cheapest moment to catch a defect is the moment it is created, while the most expensive moment is the quarter it has been feeding a compensation report. This lesson covers the vocabulary teams use to describe quality, the two Google services that enforce it, and the operating flow that turns a failed check into an owner with a ticket instead of a silent downstream surprise.
Where quality problems come from
Most defects arrive through the door rather than being made inside your warehouse. An upstream system changes a column from numeric to string, a partner shifts a file delivery from midnight to two in the morning, a mobile client starts sending timestamps without a timezone, or an upstream deduplication step is quietly turned off during an incident. The transformation code itself rarely changes on the day quality collapses.
That pattern decides where checks belong. Validation at the point of ingestion catches structural damage before it spreads, validation after each transformation catches logic errors while the offending commit is still fresh, and validation on the curated tables catches the aggregate damage that only appears once everything has been joined. Teams that check only at the end force every investigation to start from a broken number and work backwards through three pipelines to find the moment it broke.
The six dimensions and how to test them
Quality conversations go in circles until everyone uses the same words. The six dimensions below come from data management practice, and each one maps onto a check you can write today.
| Dimension | Question it answers | Typical check |
|---|---|---|
| Completeness | Are the values we expect actually present? | Count of nulls in required columns equals zero |
| Uniqueness | Does each real-world fact appear once? | Group by key having count greater than one |
| Validity | Does the value conform to its format or range? | Regex on email, bounds on amount |
| Consistency | Do two systems agree on the same fact? | Row counts or checksums across tables |
| Timeliness | Is the data available when it is needed? | Max event timestamp within a freshness window |
| Accuracy | Does it match the real world? | Compare against a trusted source of record |
Accuracy is the awkward one, because it needs an external reference. If a bank balance must match the core ledger, accuracy means a reconciliation query against that ledger rather than an internal rule, and a pipeline that validates accuracy without a reference is really testing consistency and calling it accuracy. Knowing which dimension a check covers keeps teams from celebrating a green board while the numbers remain wrong.
Dataplex data quality scans
Dataplex runs scheduled scans against BigQuery tables and grades them against rules, one per dimension, with a threshold that decides pass or fail. The scan below runs at six in the morning, checks that order identifiers are present and unique, that amounts fall inside a plausible range, and that orders are arriving daily.
from google.cloud import dataplex_v1
client = dataplex_v1.DataplexServiceClient()
scan = client.create_data_scan(
request={
"parent": "projects/my-project/locations/us-central1",
"data_scan_id": "sales-quality-scan",
"data_scan": {
"display_name": "Sales Data Quality Scan",
"data": {
"resource": "projects/my-project/datasets/analytics/tables/sales"
},
"execution_spec": {
"trigger": {
"schedule": {"cron": "0 6 * * *"}
}
},
"data_quality_spec": {
"rules": [
{
"dimension": "COMPLETENESS",
"column": "order_id",
"threshold": 1.0,
"non_null_expectation": {}
},
{
"dimension": "UNIQUENESS",
"column": "order_id",
"threshold": 1.0,
"uniqueness_expectation": {}
},
{
"dimension": "VALIDITY",
"column": "amount",
"threshold": 0.99,
"range_expectation": {
"min_value": "0",
"max_value": "1000000",
"strict_min_enabled": False,
"strict_max_enabled": False
}
},
{
"dimension": "TIMELINESS",
"column": "order_date",
"threshold": 0.99,
"freshness_expectation": {
"column": "order_date",
"max_expectation_interval": "1d"
}
}
]
}
}
}
)
Two details decide whether scans are useful. A threshold of one for completeness on a primary key is correct and should stay there, because a null key is never acceptable, whereas a validity threshold of ninety nine percent acknowledges that a small tail of odd values is normal and alerts should not fire on it. The second detail is scheduling: scans that run weekly are documentation, while scans that run with the pipeline or nightly before the business day starts are controls.
Dataform assertions at transformation time
Dataplex grades what lands in the table. Dataform assertions grade what your SQL produced, and because they run inside the same release, a failing assertion stops the deployment instead of being discovered the next morning. An assertion is a query that returns rows when something is wrong, so an empty result is a pass.
-- Dataform assertion for data quality
config {
type: "assertion",
database: "project",
schema: "analytics",
description: "Sales data quality assertions"
}
-- Check for null order IDs
SELECT *
FROM ${ref("sales")}
WHERE order_id IS NULL
-- Check for negative amounts
SELECT *
FROM ${ref("sales")}
WHERE amount < 0
-- Check for duplicate order IDs
SELECT
order_id,
COUNT(*) as duplicate_count
FROM ${ref("sales")}
GROUP BY 1
HAVING COUNT(*) > 1
Keep assertions cheap enough to run on every build, which means filtering to the partitions the current run touched rather than scanning the whole history. Assertions that take ten minutes get skipped by developers under pressure, and skipped checks quietly become no checks at all.
Quarantine, alert, and fix
When a check fails, three outcomes are possible and only two of them are acceptable. You can block the load, which is right for structural damage such as a missing column. You can load the good rows and route the bad ones to a quarantine table with the reason attached, which is right for row level defects that should not delay everything else. What you cannot do is alert and load anyway, because that trains the team to ignore the alert.
The quarantine table needs the raw payload, the failing rule, and the timestamp, so that a fix can be applied and the rows replayed rather than lost. Alert the owning team rather than a shared channel, attach a runbook link, and track the age of the oldest quarantined row as a metric, since a queue that grows for a week means the alert is going to the wrong place.
Choosing checks by layer
Different layers justify different strictness, and copying one rule set across all three creates either false alarms upstream or missing coverage downstream.
| Layer | What you check | Failure behaviour |
|---|---|---|
| Bronze or raw | Schema shape, required fields, file arrival | Reject file, alert ingestion owner |
| Silver or curated | Uniqueness, referential integrity, ranges | Quarantine rows, keep good data flowing |
| Gold or marts | Business totals, reconciliation against source of record | Block release, notify business owner |
Layered checks also give you a debugging shortcut, because a defect visible only at gold but absent at silver points at transformation logic, while a defect already visible at bronze points upstream. That distinction changes who gets paged and how quickly the conversation ends.
Measuring quality instead of asserting it
A quality programme needs a number that trends. Track the pass rate per rule over time, the count of quarantined rows per day, the mean time from detection to fix, and the share of curated tables that have at least one scan attached. A rule that never fails may be correctly calibrated or may be meaningless, so review rules that have not fired in ninety days rather than assuming they are protecting anything.
Common Mistakes
Running one hundred rules that all pass every day
Fix: Start with a handful of rules tied to real failure modes, then add only when a defect escapes; retire rules that never fire so the signal stays dense.
Alerting on a failed check without stopping the load
Fix: Block or quarantine on failure so the alert and the data agree, otherwise the team learns that red boards still mean publishable numbers.
Checking only the final curated tables
Fix: Validate at ingestion and after each transformation, so the layer where the defect appeared identifies the owner who can fix it.
Best Practices
- Attach scans and assertions to the release, not to a monthly cleanup schedule
- Quarantine bad rows with their reason and replay them after the fix instead of dropping them
- Track pass rate, quarantine age, and mean time to fix as operating metrics
Key Takeaways
- Quality defects usually arrive from upstream changes, so checks belong at ingestion and after every transformation
- The six dimensions map directly to SQL, and accuracy needs an external reference or it is really consistency
- Dataplex grades stored data on a schedule while Dataform assertions grade your SQL before it deploys
- Blocking or quarantining on failure keeps alerts trustworthy, and trusted alerts keep response times short
Interview Questions
Q1: What are the six dimensions of data quality?
Completeness, uniqueness, validity, timeliness, consistency, and accuracy. Each maps to a specific check: null counts, duplicate keys, format and range rules, freshness windows, cross-table comparisons, and reconciliation against a source of record.
Q2: When would you use Dataplex scans versus Dataform assertions?
Dataplex scans are scheduled, broad checks over tables already in the warehouse, good for monitoring and compliance evidence. Dataform assertions run inside the transformation release and fail the build, which is where logic errors should be caught. Mature teams use both for different layers.
Q3: How do you handle a data quality failure in production?
Decide whether the defect is structural or row level. Block the load for structural damage, quarantine failing rows with their rule and payload for row level issues, alert the owning team with a runbook, then replay the quarantined rows after the fix and record how long detection took.
Q4: How do you monitor data quality over time?
Track rule pass rate per rule, volume and age of quarantined rows, mean time to detect and fix, and coverage such as the share of curated tables with an active scan. Review rules that never fire, because silence can mean either good calibration or a rule that tests nothing.
Q5: Why do quality checks belong at every layer?
Because the layer where a defect first appears tells you who owns it. A problem visible at ingestion is upstream, a problem that appears only after transformation is your SQL, and a problem that surfaces at the mart layer is a business rule. Single layer checking hides that attribution.