dbt
Data transformation tool that enables analytics engineers to transform data in their warehouses.
Quick Start
-- models/staging/stg_orders.sql
WITH source AS (
SELECT * FROM {{ source('shopify', 'orders') }}
)
SELECT
id AS order_id,
customer_id,
total_price,
created_at
FROM source
When to Use
- Data warehouse transformations
- Analytics engineering
- Data quality testing
- Documentation generation
Step-by-Step
- Init:
dbt init my_project - Write SQL models in
models/ - Define sources and tests
- Run:
dbt run
Dependencies
pip install dbt-core dbt-postgres
dbt init my_project
Examples
{{ config(materialized='table') }}
SELECT
customer_id,
COUNT(*) as order_count,
SUM(total_price) as total_spent
FROM {{ ref('stg_orders') }}
GROUP BY customer_id
Resources
Validation
dbt runcompletes successfullydbt testpasses all tests- Documentation generates:
dbt docs generate