Saltar al contenido

Lección 21 · Operations, Quality and Governance

Data Quality and Reconciliation

Protect trust in your warehouse with quality dimensions, SQL tests, source reconciliation, freshness and volume monitoring, and a clear incident process.

People stop using a warehouse they do not trust. One visibly wrong number can undo months of good work. Data quality is therefore part of the design: you decide what "correct enough" means, test for it automatically and respond when a test fails.

Dimensions of quality

What can be wrong?

Completeness Is anything missing?
Accuracy Does it match reality?
Uniqueness Any duplicates?
Validity Allowed values and formats?
1 / 2

Accuracy is the hardest. A value can be valid and consistent yet wrong. Comparing with a trusted reference or asking the people who know the process is often the only way to check.

Tests that pay off

For most warehouses, start with:

  • Uniqueness of dimension keys and of the fact grain.
  • Not null for required columns.
  • Referential integrity: each fact key exists in its dimension.
  • Accepted values and sensible ranges.
  • History integrity for Type 2 dimensions.
  • Business rules, such as net amount equals gross minus discount.

A helpful convention is that a test returns the bad rows. Zero rows means pass. You can also collect all results in one summary.

SQL A small test suite in SQL

Press Run (or Ctrl + Enter) to see the result here.

Each of the four tests finds one failure. Notice channel IS NULL OR: without it, a NULL channel would pass, because NULL NOT IN (...) is not true. Frameworks such as dbt tests express checks like these as configuration.

Reconciliation

Tests check the warehouse's internal rules. Reconciliation compares the warehouse with an independent figure, usually from the source: row counts, sums and distinct keys for the same period.

Compare at a useful level of detail. A matching grand total can hide two opposite errors.

SQL Reconcile by day and find the gap

Press Run (or Ctrl + Enter) to see the result here.

The grand totals agree at 650, yet two days are wrong. This kind of error often comes from time zone handling.

This query starts from the source list, so it would not show a date that exists only in the warehouse. A complete reconciliation checks both directions. Also make sure both sides use the same cut-off time and filters, or you will chase differences that are not errors. Agree on any tolerance, for example for rounding, in advance.

Monitoring

Rule tests do not catch everything. Watch:

  • Freshness: how old is the newest data?
  • Volume: is today's row count far from the usual pattern?
  • Distribution: did the share of unknown keys or empty values jump?
  • Schema: did a source column appear, vanish or change type?

Set thresholds from your own data, allow for weekends and seasons, and tune noisy alerts. Alerts that are always firing get ignored.

Where to test and what to do

Severity Example Typical response
Critical Duplicate fact grain Stop publishing; keep the last good version
High Reconciliation gap Publish only with a warning, or hold; investigate
Low A few missing optional values Record and review

A write-audit-publish approach loads data into a hidden area, runs checks and then makes it visible only if the checks pass.

Fix problems at their source where possible. Patching values in the warehouse makes it disagree with the source and may be undone by the next load. When bad data has already reached users, tell them what was wrong, which period it affected and when it was fixed.

Agree on ownership: who is alerted, who decides and who fixes. A data contract can record what a producer promises about schema, meaning and timing, so changes are discussed before they break loads.

Turn a rule into a test

Business users describe quality in sentences. Your job is to make each sentence checkable.

Statement Test
"Every sale belongs to a store." No fact row has a store key missing from the dimension
"We never sell for a negative price." No sale line has a negative unit price; returns are checked separately
"Yesterday's data is there by the morning." The newest sale date reaches yesterday by the agreed time, allowing for closed days
"Totals match the till system." Daily sums by store equal the source's closing report within the agreed tolerance

If you cannot turn a statement into a test, ask for an example of a violation. The example usually reveals the real rule.

When a test fails

Handle a data incident with a routine:

  1. Contain. Stop publishing the affected data if readers could be misled.
  2. Scope. Find which tables, periods and reports are affected, using lineage.
  3. Diagnose. Follow the data backward through the layers to the first place it is wrong.
  4. Repair. Fix the cause, then reload the affected periods.
  5. Verify. Run the tests and reconciliation again.
  6. Learn. Add a test or a safeguard that would catch it earlier next time.

Keep a short record of each incident. Repeated causes show where to invest.

Avoid false confidence

A green test report means only that the listed rules passed. It says nothing about rules you never wrote. A table with zero rows can pass uniqueness, not-null and relationship tests, because there is nothing to violate them. That is why volume and freshness checks belong in the same suite. Also test your tests: feed a known bad row into a non-production copy and confirm that the check fails.

Start this week

Pick your most important fact table. Add a grain test, a key test and a daily comparison with the source.

Common mistakes

A hundred tests on trivial columns can distract from the few that matter. Start with keys, grain, important money measures and freshness, then add tests when you learn from incidents.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A test is written to return bad rows. What does an empty result mean?

    No violating rows were found for this rule; it does not prove everything else.
  2. 2. Why reconcile at a detail level such as per day?

    Opposite errors can cancel in a single total.
  3. 3. Which quality dimension asks whether data is recent enough?

    Timeliness is about data being available when needed.
  4. 4. What happens in write-audit-publish when a critical check fails?

    Readers keep the last good version.

Summary

  • Quality covers completeness, accuracy, uniqueness, validity, consistency and timeliness.
  • Automate tests for keys, grain, references, values and business rules.
  • Reconcile with independent figures at a useful level.
  • Monitor freshness, volume and schema, and agree on who responds.

Next: Metadata, Lineage and Semantic Layers

Tu progreso se guarda en este navegador. No necesitas una cuenta.