Saltar al contenido

Lección 22 · Operations, Quality and Governance

Metadata, Lineage and Semantic Layers

Document your warehouse with metadata, data catalogs and lineage, trace impact with a recursive SQL query, and define shared metrics in a semantic layer.

A table full of correct numbers is still useless if nobody knows what the numbers mean. Metadata is data about your data. It helps people find datasets, understand them and judge whether they can rely on them.

Kinds of metadata

Kind Answers Examples
Technical How is it built? Tables, columns, types, partitions
Business What does it mean? Definitions, owners, allowed uses
Operational How is it behaving? Last load time, row counts, failures
Social How is it used? Popular tables, certified datasets, comments

Much technical and operational metadata can be collected automatically. Business meaning needs people.

A useful table description

Write this for every important table, and keep it near the code:

Field Example
Name fact_sales
Grain One row per product line on a receipt
Owner Sales data team
Source Point-of-sale system and web shop
Refresh Daily; expected by an agreed time
Sensitive data Pseudonymous customer key
Known limits Returns are in a separate table

A data dictionary lists columns and their meanings. A business glossary defines business terms such as "active customer". A data catalog is a searchable inventory that brings these together, often with ownership, lineage and quality status. See data catalogs and lineage.

Lineage

Lineage shows where data came from and where it goes. It supports two everyday questions:

  • Root cause: this dashboard looks wrong; which upstream inputs could explain it?
  • Impact analysis: if I change this column, what breaks?

Lineage can be tracked at table level or column level. Store it as a graph of dependencies, ideally generated from the transformation code so that it stays current.

SQL Impact analysis with a recursive query

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

The first query assumes the graph has no cycles, which a one-way pipeline should not have. With a cycle, the growing depth column would keep producing new rows, so you would need a depth limit.

Lineage is only as complete as what is recorded. A spreadsheet export or a hand-written script may not appear.

The semantic layer

If five dashboards each write their own "active customers" query, you may get five answers. A semantic layer defines business concepts once, such as metrics, dimensions, joins and filters, so tools can reuse them. It might be a feature of a BI tool, a separate service, a transformation framework feature or, at its simplest, a set of governed views.

SQL Stand-in: a shared metric as a view

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

The rule here is an illustration, not accounting guidance. The people responsible for your financial reporting define how revenue is counted.

A metric definition should include:

  • A name and a plain-language description.
  • The formula, source and grain.
  • Which dimensions it can be grouped by, and its additivity.
  • Filters, time rules and currency.
  • An owner and a change history.

AI assistants and metadata

Some tools use an AI model to write SQL from a question. Clear names, descriptions and governed metrics give such a tool better context, but its output can still be wrong in ways that look plausible: a bad join, the wrong date role or a summed balance. Check the generated SQL and compare results with trusted figures. Follow your organization's rules before sharing schema details or data with any external service, and give the tool read-only, limited access.

Keeping documentation alive

  • Store descriptions with the transformation code and review them together.
  • Generate technical details automatically.
  • Check in your build that key tables have owners and descriptions.
  • Mark certified datasets so people know which to prefer, and mark deprecated ones with a removal plan.

Write a metric that cannot be misread

Take "active customers". It sounds clear until you ask questions. Does a customer become active by buying, or also by logging in? Within which period? Do returned orders count? Are test accounts excluded? Which time zone ends a month?

A usable definition might read: "The number of distinct customers with at least one completed purchase in the selected period, excluding test accounts. Fully returned orders count. Dates use the store's local time." Another team might need a different rule. In that case give the two metrics two names, instead of letting one name mean two things.

Then note the behavior under grouping. Distinct customers by store cannot be added to get the company total, because one customer may shop in two stores. The semantic layer should recount at each level.

Keep definitions testable

For important metrics, keep a small example with a known answer: a few input rows and the expected result. Run it whenever the definition or the underlying model changes. When a definition must change, record the old and new rule and the date, and say whether historical figures are restated. People comparing this month's report with an older slide need to know that the rule moved.

Start small

You do not need a large catalog project to begin. For the ten most used tables, write the grain, owner, refresh expectation and known limits. Define the handful of metrics that cause the most arguments. Put them where people already look, such as table comments or the BI tool's descriptions, generated from files in version control. Then extend coverage as questions come in. An accurate small catalog helps more than a large one full of empty or outdated entries.

Common mistakes

Documentation that only repeats a column name ("customer_id: the id of the customer") adds nothing. Describe what makes a value surprising: where it comes from, when it is empty and what it must not be used for.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which question is impact analysis designed to answer?

    It follows lineage downstream from the thing you plan to change.
  2. 2. What is the main goal of a semantic layer?

    Shared definitions keep different tools consistent.
  3. 3. Which is business metadata?

    Meaning and definitions are business metadata.
  4. 4. How should you treat AI-generated SQL on warehouse data?

    Runnable SQL can still answer the wrong question.

Summary

  • Metadata is technical, business, operational and social.
  • Catalogs help people find and understand data; lineage supports root cause and impact analysis.
  • A semantic layer defines metrics once.
  • Keep documentation close to code, and verify generated queries.

Next: Security, Governance and Cost

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