BigQuery column lineage from SQL, and what the audit log adds

· The Nistor team · 6 min read

A lineage graph is only useful if you know where each edge came from. An edge you cannot explain is an edge you cannot defend in an incident review. This post walks through where Nistor gets BigQuery lineage, the SQL, and what the audit log adds, and what each one can and cannot prove about a column.

Two sources, two jobs

Nistor builds lineage from the SQL and follows what happens through the audit log. They answer different questions.

The SQL answers "how is this table built?". At compile time, Nistor reads view definitions and the actions of Dataform compilation results to draw table edges. It parses the SQL of Dataform actions, BigQuery views and source files to draw column edges. This is the structure of your pipelines, as written.

The audit log answers "what actually happened?". Every write, read and job completion in a monitored project is logged by Google Cloud. Nistor routes those entries to itself and turns them into events, runs and, when you ask for it, evidence of each write.

Neither source is enough alone. The SQL says a column could flow from one table to another. The audit log says a job did write that table at 06:14, from those sources, with that many rows. Together they give you an edge and a reason to believe it.

What the audit log carries

The monitored_project Terraform module creates eleven log sinks in each project you monitor. They route the entries to the platform's Pub/Sub topic, where the input-logs role reads them. For BigQuery, the sinks carry:

  • job completions and child jobs;
  • table reads;
  • table data changes and table metadata changes;
  • writes through the BigQuery Storage Write API.

The same sinks carry Cloud Storage object events, Cloud Run and Cloud Functions deploys, and Data Fusion pipeline start and end lines. The BigQuery events also record the bytes billed per job, which is why cost can sit next to lineage later.

The Google Cloud integration page shows the three inputs the reference root uses to wire the module:

monitored_projects                  = ["acme-data-prod", "acme-ingest-prod"]
gcp_tool_connection_service_account = "nistor-gcp-estate@acme-nistor-prod.iam.gserviceaccount.com"
monitored_project_buckets           = { "acme-data-prod" = ["acme-landing"] }

The module needs enable_input_logs, which is true by default. By default it binds no roles. You grant the read roles yourself, or set grant_tool_roles = true and let it bind the default ones. Note that the default list has no BigQuery role: grant those in each monitored project.

From log entry to node

An audit-log entry names a table. The input-logs role matches it to a node in the graph. It forwards an event to the scheduler only when a rule listens for it, so a busy project does not flood the scheduler with writes nobody cares about.

The same entries feed two lineage features. Both are off by default.

The first is the lineage ledger. With LINEAGE_LEDGER_ENABLED set to true, the backend records an entry for each BigQuery write event it receives: inserts, merges, creates, updates, deletes, loads and streaming writes. An entry holds the destination table, the writer, the job, the source tables, the row counts and the shape of the write: an append, a merge or a full rewrite, for example.

The second is row trace. The row-trace routes read the ledger's write history of a table and, recursively, of the sources that fed each write. One route, row_journey, finds the ledger write that most likely produced one row's current state, matched from the row's SYS_* audit values. These routes need the lineage:row_trace permission, which only the tenant-admin role template holds.

The audit log also counts column reads. The API's column usage answer is aggregated from Nistor's own ingested read events whose list of fields read references the column. It makes no live call to Google Cloud.

Column by column

A column edge records, for each column of a node, its source columns and, when the SQL shows one, the expression that derives it. In the console, a node's detail panel shows a column preview when column lineage is known. Over the API, GET /lineage/columns?node_id= returns every column of a node with a one-line derivation summary and its sources.

Copies get special treatment. A field is often copied across tables or renamed on the way. Nistor walks the column edges that are pure copies, with exactly one source column and no operator, and groups the columns that hold the same field. With the relaxed setting, on by default, wrappers that keep the value also count as copies: TRIM, CAST, UPPER, LOWER, COALESCE and their relatives. A group holds at most 50 columns unless you ask for more, up to 500.

That grouping matters in practice. "Where else does customer_id live?" becomes one call instead of an afternoon of searching.

How much weight an edge can carry

Not every edge deserves the same trust, and the graph says which is which.

A parsed edge is as good as the parse. Column lineage comes from SQL, so it is only as complete as the parser's reading of that SQL. A column with no traced source has has_lineage set to false. The graph does not invent a source to fill the gap.

A confirmed edge has a write behind it. With the ledger on, impact analysis can take a since timestamp. For each affected node it then adds the first write after that time, the number of writes, the rows written, and confirmed_from_origin. That flag is true when a write lists the origin node among its sources. A structural edge says the data could flow; a confirmed edge says it did.

A missing number is not a zero. The ledger separates a measured zero from a missing measurement. A BigQuery table reports writes_since: 0 only when the window starts after the ledger's earliest entry. Any other node, or an older window, reports nothing. Read that as "not measured", never as "nothing was written".

A heuristic edge is drawn apart. Table-to-dashboard links from Castor are heuristic. Nistor draws them as a separate, badged overlay, so they never pass for parsed lineage. Storing those links needs the Catalog module, part of Nistor Enterprise.

Impact stops where the edges stop. Impact analysis follows edges in the graph and nothing else. A notebook or a service that reads a table directly, with no edge to it, is not in the answer.

What you get from it

With the structure from the SQL and the evidence from the audit log, a few questions get short answers.

  • What feeds this column? The column view, with the expression that derives it.
  • What breaks if this table is late? Impact analysis walks downstream, breadth first, three edges by default. It classifies the blast radius as critical from 20 downstream nodes, high from 10 and medium from 3.
  • Did the upstream job really write today? The ledger, if you turned it on.

Each answer names its source, so you can tell a parsed edge from an observed write.

Where to go next

The lineage page shows what the graph looks like in the console. The Google Cloud integration lists the node types and roles. For incidents that walk this graph to a probable cause, see incidents. For a whole BigQuery and Dataform estate, see the use case.

The full detail on the edges, the ledger, the sinks and the permissions is in the lineage docs.

See your platform as one graph, on your laptop. Explore the demo estate, or book a walkthrough on one like yours.