The Analytics Engineer transforms raw data into reliable, documented, tested models that business users can trust. The goal is to be the "plumber of data" - moving data from raw source tables through staging, intermediate, and mart layers, with tests at each layer that catch data quality problems before they reach dashboards.
dbt Project Structure
models/
staging/ # 1:1 with source tables, rename columns, cast types
stg_orders.sql
stg_users.sql
stg_products.sql
intermediate/ # Joins across staging models, business logic
int_order_items_enriched.sql
marts/
core/
fct_orders.sql # Fact table - one row per order
dim_users.sql # Dimension table - one row per user
marketing/
mrt_user_acquisition.sql
# Rule: marts reference intermediate/staging, never raw sources
# Rule: staging models are the ONLY place that references raw source tables
Dimensional Modeling
-- fct_orders.sql - fact table (measures + foreign keys)
SELECT
o.id AS order_id, -- Natural key
{{ dbt_utils.generate_surrogate_key(['o.id']) }} AS order_sk,
u.user_sk, -- FK to dim_users
p.product_sk, -- FK to dim_products
d.date_sk, -- FK to dim_date
-- Measures
o.quantity,
o.unit_price_cents,
o.quantity * o.unit_price_cents AS total_revenue_cents,
o.discount_cents,
-- Degenerate dimensions (stored in fact, no dim table)
o.currency_code,
o.channel
FROM {{ ref('stg_orders') }} o
LEFT JOIN {{ ref('dim_users') }} u ON u.user_id = o.user_id
LEFT JOIN {{ ref('dim_products') }} p ON p.product_id = o.product_id
LEFT JOIN {{ ref('dim_date') }} d ON d.date_day = DATE(o.created_at)
Data Quality Tests
# models/staging/schema.yml
version: 2
models:
- name: stg_orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- not_null
- accepted_values:
values: ['pending', 'completed', 'cancelled', 'refunded']
- name: user_id
tests:
- not_null
- relationships:
to: ref('stg_users')
field: user_id
- name: total_cents
tests:
- not_null
- dbt_utils.expression_is_true:
expression: ">= 0"