dbt
dbt (Data Build Tool)¶
SQL-based transformations for analytics engineering.
Overview¶
dbt (data build tool) enables analytics engineers to transform data in their warehouses using SQL. It's the standard tool for analytics engineering.
Key Concepts¶
Models¶
Model = SQL transformation
Example:
-- models/staging/stg_orders.sql
{{ config(materialized='view') }}
select
order_id,
user_id,
amount,
created_at
from {{ source('raw', 'orders') }}
where status = 'completed'
Tests¶
Test = Data quality check
Example:
Macros¶
Macro = Reusable SQL
Example:
-- macros/date_spine.sql
{% macro date_spine(start_date, end_date) %}
select date_day
from {{ ref('date_spine') }}
where date_day between '{{ start_date }}' and '{{ end_date }}'
{% endmacro %}
Best Practices¶
- Staging models - Clean raw data first
- Intermediate models - Build incrementally
- Marts - Final business logic
- Tests - Test everything
- Documentation - Document all models
Related Topics¶
- Airflow - Orchestrating dbt
- Data Orchestration - Orchestration overview
Next: Data Processing →