feat(dbt): extract dbt Jinja lineage and macros from raw .sql models - #584
feat(dbt): extract dbt Jinja lineage and macros from raw .sql models#584alexisperinger-ux wants to merge 7 commits into
Conversation
CREATE TABLE/VIEW/MATERIALIZED VIEW now extract as Table/View defs (were generic Variable nodes) and CREATE PROCEDURE as Function. FROM/JOIN relations are emitted as usages scoped to the enclosing CREATE def, so pass_usages resolves them into view->table USAGE lineage edges. The definition-registry allowlist gains Table/View so those defs resolve as edge targets (kept in sync across pass_definitions and pass_parallel). Adds extraction tests for the new labels and the lineage usages. Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 63054f04465ec33ffde0b9a23d6f29ce817d96df) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
CREATE TABLE/VIEW now produce Table/View nodes (63054f0) instead of the old Variable mislabel; update the label golden and the probe accordingly. Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 7cca3f4faec7d2a12ac1cc6f4e432c8bc286cd94) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
resolve_sql_func_name took the first identifier of object_reference (the schema) for schema.table names; take the last (the table) so CREATE TABLE/VIEW nodes and FROM/JOIN lineage use the real relation name. Adds a schema-qualified regression test. Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 877ad51e8c14daf901656d918ced2ef636f7a5b1) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 8ffee3834223ce58aa6c26b83c88f2902e07180e) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 23f81ed76a05c813a68a67bc5b1dc47344e160f0) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
…ates dbt models are .sql (the SQL host path); a plain .jinja/.j2 template is not a dbt model. Emit Model only on the SQL path; the JINJA2 path keeps macro and ref/source extraction. Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com> (cherry picked from commit 582ad0c0293be148a97e1e52d0043ad6c4fe0e7d) Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
Signed-off-by: alexisperinger-ux <alexis.peringer@iss-stoxx.com>
4ddb62a to
56a5a32
Compare
|
Huge thanks for opening this PR and for the work you put into it. The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime. |
|
Reviewed as part of your set — the direction discussion lives on #582 and this covers what is specific to #584. First, a structural thing you will want to know: this PR contains all of #582. Its first four commits are re-cherry-picks of the same four originals (same messages and (Minor related signal: the tip commit is "resolve cherry-pick conflict markers in test_extraction.c". The final diff is clean — I checked — but conflict markers were pushed at some point.) Security is clean, and I want to credit one choice specifically: you used the Three things give me pause, and they are about precision rather than safety.
What is genuinely good here: raw dbt models really are code sitting in indexed repositories, they index today as broken SQL with zero lineage, and your design reuses the existing usage-resolution pass rather than inventing parallel machinery. The three dbt tests are binding. This is not a drive-by. It also inherits #582's issues — the stale registry anchors and the third keep-in-sync site at Please hold off reworking until the maintainer answers the direction question on #582. This is the PR that most depends on that answer, and rebasing 462 lines against moved anchors is a poor use of your time before the concept is settled. |
Summary
dbt
.sqlmodels are Jinja-templated, so without a compiled manifest a model and its dependencies are invisible to the graph: a referenced model likestg_usersis not even a node. This indexes raw (uncompiled) dbt models:{{ ref('m') }}/{{ source('s','t') }}becomeUSAGElineage edges, via the vendoredtree-sitter-jinja2grammar..sqlfile with no macro defs) becomes aModelnode keyed by file stem, so cross-file{{ ref('that_model') }}resolves into model-to-model lineage.{% macro name(...) %}becomes aMacronode.Modelis emitted only on the.sqlpath, so a plain.jinja/.j2template is not treated as a model, and a macro-defining file is treated as a library, not a model.No schema change: freeform
Model/Macrolabels and the existingUSAGEedge type.Index mode: macro extraction is gated to full mode, so the new nodes need a full-mode index.
Tests:
dbt_jinja_macro_defs,dbt_jinja_ref_lineage,dbt_sql_ref_lineageintests/test_extraction.c.Complements the authoritative manifest path (#583).
Fixes #575.
Related PRs
This is one of three PRs that split the SQL + dbt graph-indexing work to keep each under the one-issue-per-PR contributing rule. They share the same extraction and registry plumbing, so they are one logical change reviewed as a set:
Table/Viewnodes + FROM/JOIN lineage (#574)..sql,Model/Macronodes +ref()/source()lineage (#575).Model/Sourcenodes +DEPENDS_ONlineage (#576).