Data lineage
Data lineage explains how a pipeline asset depends on other assets and how its output columns relate to source columns. Bruin derives this view from declared asset links and rendered SQL queries. It exposes the result through the asset lineage command, machine-readable parse workflows, and visual lineage views. See Data governance, Quality policies and linting, and Semantic layer engine for related governance features.
Lineage model
Asset graph
The asset graph is a directed graph of pipeline assets. An upstream asset supplies data to a downstream asset. Bruin keeps both directions so an engineer can trace inputs and assess which assets a change may affect. Direct lineage shows immediate neighbors. Full lineage follows the graph beyond those neighbors and removes repeated assets.
This diagram shows how a source can affect a report through a transform.
flowchart LR
source[Source asset] --> transform[Transform asset]
transform --> report[Report asset]
source -. full downstream .-> report
An asset dependency can point to another pipeline asset or to an external URI. Bruin reports an external URI as an external source. It does not treat that URI as a local asset that can be inspected or traversed. References: pkg/…/pipeline.go• L1172-1183, pkg/…/pipeline.go• L1723-1745, cmd/lineage.go• L109-117
Column graph
The column graph adds links inside the asset graph. An output column can point to one or more source columns. These links describe direct copies, renamed fields, expressions, joins, and filters that use source columns even when those columns are not in the output.
Column links remain attached to the output column and to the relevant upstream dependency. This connects field-level tracing to the asset dependency used for scheduling and impact checks. References: pkg/…/pipeline.go• L846-882, pkg/…/lineage.go• L279-370
Lineage derivation
Pipeline metadata
Lineage starts with the materialized pipeline model. Pipeline creation resolves declared dependencies into asset links and fills derived asset names. The selected variant and its rendered dependency names must be present before Bruin builds the graph.
Asset column declarations provide the known schemas for query analysis. A table that has no local asset remains an external reference for column lineage. A selected connection can also provide the namespace needed to match a qualified query table to a local asset. The lineage extractor also accepts an asset-to-database map. A matching database-qualified table name resolves to the canonical local asset; a table with a different database remains external. References: cmd/lineage.go• L68-88, pkg/…/lineage.go• L45-99, pkg/…/lineage_test.go• L1919-1960
Template pipelines can declare source assets for external warehouse data so lineage starts at a named pipeline node. In the Google Web Analytics template, staging models point to stable source assets for exported tables, and asset names follow the dataset and table names used by the queries. References: cmd/lineage.go• L68-88, pkg/…/lineage.go• L50-77, cmd/internal.go• L398-448, cmd/init_template_test.go• L707-783
Query analysis
For a SQL asset, Bruin renders the query and sends it with known upstream schemas to the SQL parser. The parser returns output columns, source links, query-used columns that are not selected, inferred types, and analysis errors. When the pipeline has a definition path, rendering can use the repository root so query includes resolve in the same scope as the pipeline.
The analysis connects query structure to source fields. It supports common structures such as joins, aliases, expressions, aggregates, and nested queries. It also handles table-name case differences when it matches query tables to supplied schemas. References: pkg/…/lineage.go• L136-198, pkg/…/lineage_test.go• L45-73, pkg/…/parser.go• L150-198, pythonsrc/…/main.py• L278-345, pythonsrc/…/main.py• L377-460
Recursive enrichment
Column derivation processes upstream assets before the selected asset. This order makes upstream column data available when Bruin analyzes a downstream query. A processed-asset set prevents repeated work when graph paths meet.
The result enriches asset metadata in memory. It adds missing output columns, keeps explicit local metadata, fills missing type and descriptive metadata from upstream columns, and expands wildcard projections from known upstream columns. It combines source links without duplicates. It also records query-used columns that are not selected so filters and joins remain visible in the dependency view. Constraints and defaults that belong to an upstream definition do not become constraints or defaults on a derived column. References: pkg/…/lineage.go• L102-134, pkg/…/lineage.go• L200-277, pkg/…/lineage.go• L279-474, pkg/…/lineage_test.go• L1026-1670
Lineage workflows
Asset dependency command
The bruin lineage command reports the dependency graph for one asset. It finds the pipeline root from the given asset path, materializes the pipeline, resolves derived asset names, and then selects the target asset. By default it reports direct upstream and downstream assets. The --full flag reports all reachable assets in both directions.
The command supports two output forms:
- Plain output lists local assets with their relative paths. It also lists declared URI dependencies as
EXTERNALupstream entries. - JSON output returns the target asset name and type with structured upstream and downstream summaries. Local entries include asset metadata. External entries include their URI and an external marker.
Use --variant when the pipeline has variants and the selected variant changes its graph. The command requires the path to the asset definition itself and requires that the path be inside a pipeline. References: cmd/lineage.go• L14-42, cmd/lineage.go• L62-117, cmd/lineage.go• L122-189, docs/…/lineage.md• L1-23
Parsed asset workflow
bruin internal parse-asset --column-lineage returns one parsed asset with column links. It still loads the containing pipeline because the analysis needs upstream assets and their schemas. Its JSON response keeps lineage issues separate from asset data so callers can use partial results.
bruin internal parse-pipeline --column-lineage applies the same derivation to every asset and returns the enriched pipeline. These workflows provide machine-readable metadata for tools that need field relationships rather than the focused dependency summary from bruin lineage. References: cmd/internal.go• L64-124, cmd/internal.go• L451-580, cmd/internal.go• L586-751
Visual lineage view
The VS Code lineage panel presents the same asset and column relationships as an interactive graph. It supports direct or expanded upstream and downstream views, asset or pipeline scope, and column-level paths. A selected node links back to its asset file.
This view helps an engineer assess the effect of a change without reading raw JSON. The editor and CLI therefore depend on the same relationship model. References: docs/…/lineage-panel.md• L1-21, docs/…/lineage-panel.md• L23-55
Query and graph boundaries
External data references
A query can read a table that is not an asset in the loaded pipeline. Bruin keeps that table as an external source instead of creating a local asset. This preserves the outside data dependency while limiting local graph traversal to known assets.
A qualified table name can resolve to a local asset when its database, catalog, or project namespace matches the selected connection or asset database mapping. When no local match exists, the column link keeps the table name from the query. References: pkg/…/lineage.go• L45-69, pkg/…/lineage.go• L302-328, pkg/…/lineage_test.go• L1919-1960, cmd/lineage.go• L109-115
Analysis limits
Lineage is a static view of declared assets and rendered query text. It does not prove that a warehouse query will run or that an external table has the expected schema. Unsupported SQL, missing upstream assets, render errors, and queries above the parser length limit can produce issues or incomplete column links.
The asset command reports an error when it cannot build the requested pipeline or locate the target. Parse workflows can return the asset or pipeline with issue summaries. This lets machine readers separate usable metadata from failed analysis. References: pkg/…/parser.go• L168-197, pkg/…/lineage.go• L146-183, cmd/lineage.go• L68-93, cmd/internal.go• L705-751
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to pipeline materialization must keep derived asset names, variant selection, declared links, reverse links, and direct or full traversal aligned.
- Changes to the
bruin lineagecommand must preserve its asset-path requirement, external upstream reporting, plain output, and JSON output contract. - Changes to the SQL parser response must preserve the
columns,non_selected_columns, anderrorsdata used by the lineage extractor and parse commands. - Changes to asset names, variants, connection namespaces, database mappings, or query rendering must be checked against both asset matching and column-source matching.
- Changes to column metadata must preserve the distinction between a column's own properties and its query-derived source links.
- Changes to parse output must be reviewed with the CLI, editor lineage view, and machine readers of parsed pipeline JSON.
- Changes to template source assets or warehouse table names must keep declared upstream links aligned with the tables read by staging queries.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The asset path is empty, points to a directory, or is outside a pipeline | bruin lineage stops before it can select the target asset | Pass the asset definition file path from inside a pipeline root |
| The requested file is not a loaded asset | The command cannot produce a dependency summary | Use the exact asset definition path |
| A variant is not selected when it changes asset names or links | The graph can describe a different materialized pipeline | Pass --variant for variant pipelines |
| A query names an asset that is not in the loaded pipeline | The dependency stays external or column analysis reports an upstream issue | Declare the asset or model the source as an external URI |
| Query rendering or SQL parsing fails | Column links may be absent and lineage issues are reported | Use a renderable query with syntax supported by the asset dialect |
| A query includes a file but the pipeline has no usable repository root | Rendering can fail before column lineage is built | Run the analysis from a pipeline with a valid definition path and repository root |
| A query exceeds the parser length limit | Column lineage analysis is skipped for that query | Split the query or rely on asset-level dependencies |
| A connection or asset database namespace does not match a qualified table name | A local table can be treated as external | Check the selected connection and database mapping |
Key files
| File | Why to read it |
|---|---|
| cmd/lineage.go | Defines the focused asset-level command, its graph scope, and its plain or JSON output. |
| pkg/…/pipeline.go | Defines asset dependencies, column source links, and direct or full graph access. |
| pkg/…/lineage.go | Shows how rendered queries, upstream schemas, and database-qualified table names become asset and column lineage. |
| pkg/…/parser.go | Defines the query-lineage response contract used by the Go lineage flow. |
| pythonsrc/…/main.py | Defines the query analysis boundary and its output and error data. |
| cmd/internal.go | Defines machine-readable asset and pipeline parsing with optional column lineage. |
| docs/…/lineage.md | Gives the user-facing command syntax and supported flags. |
| docs/…/lineage-panel.md | Describes the interactive asset, pipeline, and column-level views. |
| pkg/…/lineage_test.go | Shows the contracts for recursive SQL lineage, query rendering scope, metadata merge, and qualified asset matching. |
| cmd/lineage_test.go | Shows the command contract for direct and full graphs, external sources, derived names, and error cases. |
| cmd/init_template_test.go | Shows the template contract that keeps declared warehouse source assets connected to staging-query lineage. |