snowflake
dbt Staging Model Lineage
Compiled SQL from a typical dbt staging → intermediate → mart layering. Column lineage shows source freshness from source tables to mart columns.
The lineage
The SQL
CREATE TABLE raw_app.users (
id NUMBER,
email STRING,
signup_at TIMESTAMP,
plan STRING
);
CREATE TABLE raw_app.events (
event_id STRING,
user_id NUMBER,
event_name STRING,
occurred_at TIMESTAMP
);
CREATE OR REPLACE VIEW analytics.stg_users AS
SELECT
id AS user_id,
email,
signup_at,
plan
FROM raw_app.users;
CREATE OR REPLACE VIEW analytics.stg_events AS
SELECT
event_id,
user_id,
event_name,
occurred_at
FROM raw_app.events;
CREATE OR REPLACE VIEW analytics.int_user_activity AS
SELECT
u.user_id,
u.plan,
COUNT(e.event_id) AS event_count,
MAX(e.occurred_at) AS last_event_at
FROM analytics.stg_users u
LEFT JOIN analytics.stg_events e ON e.user_id = u.user_id
GROUP BY u.user_id, u.plan;
CREATE OR REPLACE VIEW analytics.mart_active_users AS
SELECT user_id, plan, event_count, last_event_at
FROM analytics.int_user_activity
WHERE event_count >= 5;
What the lineage shows
- mart_active_users.event_count flows from raw_app.events.event_id via stg_events.
- mart_active_users.plan flows from raw_app.users.plan via stg_users.
- Visualizing compiled dbt SQL avoids needing to mentally re-walk ref() chains.