跳到正文

第 15 课 · Metadata, Catalogs and Lineage

Data Lineage

Learn data lineage at table and column level, how to collect it, and how to run impact analysis and root cause tracing with graph code and recursive SQL.

Data lineage shows where data comes from, how it is transformed and where it goes. It answers two everyday questions:

  • Backward: "This number looks wrong. Where did it come from?"
  • Forward: "I want to change this field. What will break?"

The first is root cause tracing; the second is impact analysis.

A lineage graph

Lineage is a directed graph. Nodes are datasets, columns, jobs or reports. Arrows point from inputs to outputs.

flowchart LR
  A["crm.customers"] --> C["clean.customers"]
  B["shop.orders"] --> D["clean.orders"]
  C --> E["mart.revenue_by_region"]
  D --> E
  E --> F["Executive dashboard"]
  D --> G["Fraud model"]

A change to shop.orders can affect both the dashboard and the fraud model.

Levels of detail

Level Shows Use
Business Systems and processes Explaining flows to leaders and auditors
Table or dataset Which tables feed which Impact analysis
Column Which fields produce which fields Precise debugging and sensitive data tracking

Column-level lineage is the most useful and the hardest to maintain. Collect the level you will actually use.

Collecting lineage

  • Manual documentation is quick to start but goes stale.
  • Parsing code, such as SQL transformations, extracts inputs and outputs. It struggles with dynamic SQL and custom code.
  • Runtime events are emitted by jobs as they run, recording what they actually read and wrote. OpenLineage is one open standard for this kind of event; check its official site for supported integrations.
  • Tool metadata from transformation, orchestration or catalog products.

Combine methods and be honest about gaps. Spreadsheet exports, email attachments and manual copy-and-paste often leave no trace.

Impact analysis in code

To find everything downstream, walk the graph forward. The same code walks backward if you reverse the arrows.

Python Find upstream sources and downstream impact

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

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The seen set stops the walk from looping forever if the graph contains a cycle.

Lineage with recursive SQL

If lineage edges are stored in a table, a recursive query does the same job.

SQL Trace downstream assets with a recursive query (SQL)

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

The depth limit is a safety net against cycles. Learn more about recursive queries.

Column-level thinking

Column lineage also records how a value is transformed:

Output column Inputs Transformation
mart.revenue.net_amount orders.amount, refunds.amount sum(amount) minus sum(refunds)
mart.revenue.region customers.country_code lookup in region mapping

Knowing the transformation helps you spot subtle errors, such as refunds subtracted twice.

Where lineage pays off

  • Change management: warn owners of affected assets before a change.
  • Incident response: trace a bad value to its first wrong step and list what was affected.
  • Privacy: find where a personal data field has been copied, which matters for deletion and access requests.
  • Audit: show how a reported figure was produced.
  • Cleanup: find datasets that nothing uses, then confirm with owners before removal. Absence of recorded lineage does not prove nobody uses them.

Lineage that is wrong or incomplete creates false confidence. Show when it was last updated and mark known blind spots, such as manual exports.

A worked example: tracing a wrong figure

A fictional water utility reports unusually high usage in one district. Walking backward from the dashboard, the analyst finds a monthly summary table, then a cleaned readings table, then the raw meter feed. At each step she compares a few meters. The raw feed values are normal, but the cleaned table shows them multiplied by 1,000. A recent change assumed all meters report in cubic meters and converted them to liters, while one supplier already reports in liters.

Lineage made the search short: instead of checking every system, she followed one path and compared values at each hop. Then she walked forward from the faulty step to find every other report that used the wrong values, and told their owners. Both directions mattered.

Keeping lineage current

Lineage that is collected automatically should show the time of its last update. For manual links, add an owner and review date. Make documenting new flows part of the definition of done for data work. When you find a flow that was missing, such as a monthly export that someone emails to a partner, add it and note how it was discovered. Those findings tell you where automatic collection is blind.

Try it yourself

Pick one number from a report you know and trace it backward by hand. At each step, write down the input, the transformation, the owner and how you know the link is real: code, a job log or a person's memory. Mark the links that depend only on memory. Then walk forward from one source field and list everything that would be affected if its meaning changed.

Choosing how detailed to be

Detail has a maintenance cost. Start with table-level lineage for important reports, then add column-level detail for sensitive fields and for calculations that people often question. A small, current map of what matters is more useful than a huge diagram that nobody trusts. When a diagram becomes too large to read, filter it to the neighborhood of one asset.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. You want to rename a column and need to know what could break. Which analysis do you run?

    Forward lineage shows downstream dependents.
  2. 2. Which lineage level helps most to track copies of a personal data field?

    Column lineage shows where a specific field travels.
  3. 3. A dataset shows no downstream lineage. What should you conclude?

    Lineage can miss manual or external uses.

Summary

  • Lineage is a directed graph from sources through transformations to uses.
  • Walk it backward for root causes and forward for impact.
  • Collect it from code, runtime events and tools, and document gaps.
  • Column lineage supports debugging and privacy work.
  • Treat missing lineage as unknown, not as proof of no use.

Next: Master Data Management

你的学习进度保存在此浏览器中,无需账号。