You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature: extract table-to-table dependencies from INSERT/CTAS/MERGE, not just CREATE VIEW #1572
Build a table-to-table dependency (lineage) graph from a SQL/ETL codebase — "table A is populated from tables B and C".
Current behavior (v0.9.3, extract_sql in extract.py)
.sql is parsed via tree-sitter-sql and produces good schema structure, but dataflow edges are only walked (_walk_from_refs) inside create_view, create_function, and create_procedure. As a result:
CREATE TABLE … AS SELECT … (CTAS) → emits the table node but noreferences edges to the source tables in its SELECT.
INSERT INTO tgt SELECT … FROM src … → produces nothing (no target node, no source edges).
MERGE INTO … USING … / UPDATE … FROM … → not handled.
On a real ETL repo (~700 .sql files, mostly INSERT … SELECT bodies), only ~16% of files yielded any node, and essentially zero source→target lineage edges.
Requested feature
Extend extract_sql to emit references/reads_from edges from the FROM/JOIN tables to the write target for:
INSERT INTO <tgt> … SELECT … FROM/JOIN <src…>
CREATE TABLE <tgt> AS SELECT … FROM/JOIN <src…> (CTAS)
MERGE INTO <tgt> USING <src> and UPDATE <tgt> … FROM <src>
i.e. reuse the existing _walk_from_refs logic for these statement types so a lineage graph can be built directly.
Nice-to-have
Register .ddl as a SQL/code extension (some projects keep CREATE TABLE schemas in .ddl files, currently ignored).
Optional hook to normalize templated identifiers (e.g. {project}.{dataset}.tbl from Python .format()/Jinja) so placeholder table names resolve instead of becoming literal node labels.
Happy to help test against a real ETL corpus. Thanks for graphify!
Independent corroboration on a different corpus shape, in case a second data point helps prioritise this.
Setup: graphifyy 0.9.31, tree-sitter-sql 0.3.11, extract --code-only --force over a Databricks medallion codebase (bronze → silver → gold, Unity Catalog three-part names). Not the INSERT … SELECT shape in the original report; this corpus is almost entirely CREATE OR REPLACE TABLE … AS SELECT.
In the .sql sources
In graph.json
FROM / JOIN table references
189
7reads_from edges
CREATE TABLE statements
66
—
Distinct tables referenced
79
14 nodes
So ~4% of lineage edges and ~18% of tables, closely matching the ~16% node yield reported above.
The 7 edges that did resolve are all flat FROM <table> reads inside data-dictionary builders against information_schema. That suggests one addition worth folding into the request: it is not only the statement type (CTAS/INSERT/MERGE) but also where the source sits inside the SELECT. Even once CTAS is walked, a direct FROM <table> is the rarer shape in real pipeline SQL. Sources are usually one level down, in a CTE or a subquery:
-- (a) flat CTAS — the case most likely to be fixed firstCREATE OR REPLACETABLEcat.silver.ordersASSELECT*FROMcat.bronze.orders;
-- (b) CTAS whose source is inside a CTE — the dedupe pattern, extremely commonCREATE OR REPLACETABLEcat.silver.customersAS
WITH d AS (
SELECT*, row_number() OVER (PARTITION BY id ORDER BY _ingested_at DESC) rn
FROMcat.bronze.customers
)
SELECT*FROM d WHERE rn =1;
-- (c) CTAS whose sources are a subquery plus a JOINCREATE OR REPLACETABLEcat.gold.fact_orderASSELECT o.*, c.segmentFROM (SELECT*FROMcat.silver.orders WHERE status ='complete') o
LEFT JOINcat.silver.customers c USING (customer_id);
Expected reads_from: bronze.orders → silver.orders, bronze.customers → silver.customers, and both silver.orders → gold.fact_order and silver.customers → gold.fact_order.
Actual: none of the four.
If _walk_from_refs is extended to these statement types, recursing through cte/with_clause and nested subquery nodes rather than only the top-level from_clause would be what makes it useful on real ETL rather than only on the flat case.
One consumer-side note, offered as a suggestion rather than a complaint: the shortfall is currently silent. The graph builds cleanly, reports a healthy node count, and shows a small number of confident reads_from edges with nothing indicating that most are missing. A reader who did not go and count the FROM clauses by hand would reasonably conclude the pipelines are only loosely connected. A warning in the same style as the existing missing-grammar notice would help, something like N CREATE TABLE … AS SELECT statements produced no lineage edges (see #1572). That would have saved me the manual count, and it is probably cheap next to the extraction work itself.
Happy to re-run the counts against a build once this lands.
Activity
silversaddleai-create commentedon Aug 1, 2026
Independent corroboration on a different corpus shape, in case a second data point helps prioritise this.
Setup:
graphifyy0.9.31,tree-sitter-sql0.3.11,extract --code-only --forceover a Databricks medallion codebase (bronze → silver → gold, Unity Catalog three-part names). Not theINSERT … SELECTshape in the original report; this corpus is almost entirelyCREATE OR REPLACE TABLE … AS SELECT..sqlsourcesgraph.jsonFROM/JOINtable referencesreads_fromedgesCREATE TABLEstatementsSo ~4% of lineage edges and ~18% of tables, closely matching the ~16% node yield reported above.
The 7 edges that did resolve are all flat
FROM <table>reads inside data-dictionary builders againstinformation_schema. That suggests one addition worth folding into the request: it is not only the statement type (CTAS/INSERT/MERGE) but also where the source sits inside the SELECT. Even once CTAS is walked, a directFROM <table>is the rarer shape in real pipeline SQL. Sources are usually one level down, in a CTE or a subquery:Expected
reads_from:bronze.orders → silver.orders,bronze.customers → silver.customers, and bothsilver.orders → gold.fact_orderandsilver.customers → gold.fact_order.Actual: none of the four.
If
_walk_from_refsis extended to these statement types, recursing throughcte/with_clauseand nestedsubquerynodes rather than only the top-levelfrom_clausewould be what makes it useful on real ETL rather than only on the flat case.One consumer-side note, offered as a suggestion rather than a complaint: the shortfall is currently silent. The graph builds cleanly, reports a healthy node count, and shows a small number of confident
reads_fromedges with nothing indicating that most are missing. A reader who did not go and count theFROMclauses by hand would reasonably conclude the pipelines are only loosely connected. A warning in the same style as the existing missing-grammar notice would help, something likeN CREATE TABLE … AS SELECT statements produced no lineage edges (see #1572). That would have saved me the manual count, and it is probably cheap next to the extraction work itself.Happy to re-run the counts against a build once this lands.