dbt — a tool for transforming data in a warehouse via SQL. Paradigm: define models as SQL select statements, dbt compiles the DAG, materialises into tables/views, runs tests, generates docs. The core of what is called the "modern data stack". Open-source dbt-core + SaaS dbt Cloud. Used by: Airbnb, Monzo, HelloFresh, thousands of startup data teams.
Below: details, example, related terms, FAQ.
Free online tool — HTTP header checker: instant results, no signup.
-- models/orders_summary.sql
{{ config(materialized='table') }}
SELECT
DATE_TRUNC('day', order_date) AS day,
COUNT(*) AS orders,
SUM(amount) AS revenue
FROM {{ ref('orders') }}
WHERE status = 'completed'
GROUP BY 1
-- schema.yml
models:
- name: orders_summary
columns:
- name: day
tests: [not_null, unique]dbt (Data Build Tool) is an open-source command-line tool that enables data analysts and engineers to transform raw data into a structured format for analysis, leveraging SQL. It facilitates data transformation workflows through modular SQL files, version control, and a robust testing framework, making it essential for modern data analytics pipelines.
dbt (Data Build Tool) serves as a powerful framework for transforming and modeling data within a data warehouse. It operates primarily on SQL and integrates seamlessly with various data platforms such as Snowflake, BigQuery, and Redshift. The essence of dbt lies in its ability to manage data transformation workflows efficiently, allowing data practitioners to focus on analysis rather than data engineering.
At its core, dbt uses a straightforward command-line interface (CLI) that allows users to execute a series of SQL transformations defined in .sql files. These files are organized into models, which represent the transformed data tables or views. Each model is defined by a SQL query that can reference other models, facilitating a modular and reusable architecture.
Key concepts in dbt include:
dbt's configuration allows for different materialization strategies, which dictate how and when data is written to the warehouse. For example, the table materialization creates a table every time the model is run, while the incremental materialization updates only new or changed records, thus optimizing performance and resource usage.
To illustrate the usage of dbt, let’s walk through the process of setting up a simple dbt project that transforms a raw sales dataset into a structured format suitable for reporting.
1. Installation: First, ensure you have Python and pip installed, then run:
pip install dbt2. Create a new dbt project: Use the following command to initialize a new project:
dbt init my_dbt_projectThis command creates a directory structure for your dbt project, including folders for models, seeds, and tests.
3. Configure your dbt profile: Edit the profiles.yml file to include connection details for your data warehouse. Here’s an example configuration for Snowflake:
my_profile:
target: dev
outputs:
dev:
type: snowflake
account: your_account
user: your_user
password: your_password
role: your_role
database: your_database
warehouse: your_warehouse
schema: your_schema
4. Create a model: In the models directory, create a new SQL file named sales_summary.sql with the following content:
SELECT
customer_id,
SUM(amount) AS total_sales
FROM
{{ ref('raw_sales') }}
GROUP BY
customer_id
In this example, raw_sales represents another model or table in your data warehouse. The ref function creates a dependency, ensuring that dbt builds the raw_sales model before sales_summary.
5. Run your dbt project: Execute the following command to compile and run your dbt models:
dbt runThis command will execute all models in your project, creating the necessary tables or views in your data warehouse. You can also run tests using:
dbt testBy following these steps, you've successfully set up a basic dbt project that transforms raw sales data into a summary format, showcasing dbt's capabilities in managing data transformation workflows.
Core: free, CLI, self-host. Cloud: SaaS + web IDE + scheduling + docs hosting + CI/CD, $100-200/dev/mo. For small teams — core + Airflow; enterprise — Cloud.
SQLMesh (newer, Python-based), Apache Airflow tasks, Dataform (Google). For non-SQL ELT: Fivetran/Airbyte + Python.
materialized="incremental" + unique_key — dbt detects changed rows, runs INSERT/UPDATE only for them. Huge cost savings vs full refresh.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.