table and column lineage · 11 dialects · dbt compiled folders

SQL Data Lineage

Paste SQL or open a folder of .sql files to see which tables feed which, and which source columns reach each output column as a copy, an expression or an aggregate. Filters, joins and group-bys are shown as separate dependencies. Statements the parser cannot read are listed, and the rest still run.

SQL

Drop .sql files

Up to 3000 files, 40 MB in all

Or choose a folder (dbt target/compiled)

Every .sql file inside is read

The SQL is read in this tab. Dynamic SQL and stored procedure bodies are not followed. Names are compared in lower case.

Load SQL or press an example to see the graphs.

SQL Data Lineage

Operator: Abdulla Al Fahad. How tools are built and checked

Before dropping a column, someone has to find every statement that reads it. Grep finds the name but not the alias it travels under, the CTE it passes through or the aggregate it ends up inside. This page parses the SQL, follows each output column back through CTEs, subqueries, joins and unions to the base tables, and labels each link as a copy, an expression or an aggregate.

Key features

  • Eleven dialects: PostgreSQL, MySQL, MariaDB, BigQuery, Snowflake, Redshift, SQL Server, Hive and Spark, SQLite, Trino and Athena, each loaded as its own parser build only when chosen
  • Table graph and column trace: provenance (everything upstream of a column) and impact (everything downstream)
  • Statements read: SELECT with CTEs, subqueries, joins, USING and set operations; INSERT ... SELECT with column lists; CREATE TABLE and CREATE VIEW ... AS; WITH placed before INSERT; MERGE; UPDATE ... FROM
  • Filter, join and group-by columns are kept as separate dashed dependencies of the target, apart from the columns that feed each output
  • An optional schema (CREATE TABLE text or an information_schema CSV) expands SELECT * and settles unqualified columns
  • Exports: SVG, PNG, Mermaid, a CSV edge list and OpenLineage-style JSON
  • A dbt mode: a file holding one SELECT is a model named after the file, and tables are matched by their last name part

How statements are read and what each edge means

Only the query inside a statement goes to the parser. The outer shape (CREATE, INSERT, MERGE, UPDATE) is read by the page itself, because parser support for those forms differs between dialects. A statement the parser cannot read is listed with its line and the run continues with the next one.

Names are compared in lower case with quotes, brackets and backticks removed. A BigQuery name written as one backticked token with dots, such as project.dataset.table, stays one name; other dialects join database, schema and table with dots. With the match-by-name option, only the last part counts, which is what a dbt compiled folder needs since a model is written by file name and read as database.schema.name.

How it works

Each query is resolved in a scope of relations. A CTE or a subquery in FROM becomes a relation with known output columns; a base table has columns when the schema or an earlier statement gave them. A column reference is resolved by its qualifier, or by searching the relations for the column name, nearest scope first.

A column found in several relations that could hold it is attributed to all of them and marked ambiguous, and the unresolved note says which tables it could come from. A qualifier that is not in the FROM clause is read as a table of that name and noted.

Dependency kinds combine on the way up. A bare column reference is a copy; anything wrapped in a function, operator, CASE or cast is an expression; an aggregate is an aggregation; the strongest kind along a path wins. WHERE, HAVING and QUALIFY columns become filter dependencies, ON and USING columns join, GROUP BY columns group.

MERGE and UPDATE ... FROM are turned into one SELECT per assignment over the target and the source, so the same resolver gives their column links.

Common use cases

  • An analyst asked to rename raw.customers.region opens the impact trace and sees the one column it feeds, mart.regions.region, before touching the table.
  • A data engineer loads five compiled dbt models and gets 8 tables and 8 table links, the same shape as the model graph, and uses the column trace to see that customer_lifetime_value comes from raw_payments.amount through a sum.
  • A reviewer whose migration script fails on a few statements in one dialect switches to another dialect and sees which of those statements the other grammar reads; the rest stay in the parse-error list with their line numbers.

How to use this tool

  1. Paste SQL, drop .sql files, or choose a folder such as dbt's target/compiled.
  2. Choose the dialect that matches the SQL; a statement that parses in one dialect often fails in another.
  3. Add a schema if the SQL uses SELECT * or unqualified columns across several tables.
  4. Press Analyse lineage and read the counts of statements, tables and column links.
  5. Use the table graph for the overview, then pick a table, a column and a direction in Column trace.
  6. Export the graph as SVG, PNG or Mermaid, or the edges as CSV or OpenLineage-style JSON.

Example

The Example script button: three CREATE TABLE statements, a view over a CTE, an INSERT with UNION ALL, a WITH before INSERT and a MERGE

CREATE VIEW mart.order_totals reads a CTE o that sums raw.orders.amount per customer where status = 'paid', joins raw.customers, and exposes total; INSERT INTO mart.cust_summary (cust, total_amount, name) reads that view and raw.legacy.

What is found

7 statements, 4 of them with lineage; 6 tables; 17 links of which 11 are column links (9 direct copies, 1 expression, 1 aggregation) and 6 are filter, join or group-by dependencies. raw.orders.amount feeds mart.order_totals.total as an aggregation, and total feeds mart.cust_summary.total_amount as a copy, so provenance of that column lists mart.order_totals.total and raw.orders.amount.

Tips for best results

  • Switch the dialect when a statement fails on valid SQL. The error names the line and column inside the file, and the other statements are unaffected.
  • Paste the information_schema.columns output of the real database as the schema: SELECT * then expands to real column names, and unqualified columns stop being ambiguous.
  • Tick the dashed dependencies only when you ask what a change could break, not just what it feeds; a column used in a WHERE affects every row of the target.
  • Download the Mermaid text to keep a lineage diagram in a repository's documentation.

Common pitfalls

COUNT(*), constants and CURRENT_DATE have no source column, so the output column appears with no incoming links. That is correct, not a lost link.

Dynamic SQL, stored procedure bodies and statements built by templates are not followed. Compile dbt or Jinja templates first, and give the page the compiled output.

Common errors and how to fix them

Unexpected token (line N, column M)
The parser for this dialect could not read the statement. Check the dialect first; QUALIFY, LATERAL FLATTEN, INTERSECT and a few cast forms are only read by some dialect builds.
Column x is not qualified and could come from a or b
Two tables could hold the column and no schema says which. The links to both are drawn dashed as ambiguous; add the schema or qualify the column.
No statement produced lineage
The input holds only definitions, VALUES inserts or statements that read no table. Add the statements that move data.

Best practices

  • Analyse the compiled SQL of a dbt project rather than the model files, so that every ref and macro is already resolved.

Frequently asked questions

Why does SELECT * show up as a single wildcard link?

Without a schema or an earlier CREATE statement the columns of the source are unknown, so the link goes from table.* to the target. Add the table's CREATE TABLE statement or an information_schema CSV and the star expands to one link per column.

How are window functions classified?

As expressions. The columns in PARTITION BY and ORDER BY of the window feed the output column along with the function's arguments. An aggregate without OVER is an aggregation.

Is the JSON export valid OpenLineage?

It is OpenLineage-style: run events with inputs, outputs and a columnLineage facet holding fields and dataset-level inputs. It has not been checked against the OpenLineage schema, so validate it before sending it to a collector.

Why can a dbt model name match a fully qualified table?

The match-by-name option keys every table by its last name part. A model file named customers.sql and a reference to analytics.main.customers become the same node.

How big can the input be?

Up to 40 MB across 3,000 files, 6,000 statements per file, and 120,000 characters for one statement sent to the parser. Beyond those limits the page says what it skipped.