Request a demo

Glossary · Pipelines and tooling

What is dbt (data build tool)?

dbt (data build tool) turns SELECT statements into tables and views in the warehouse: you write models as SQL with Jinja templating, and dbt builds them in dependency order, tests them and documents them. On BigQuery it runs through the dbt-bigquery adapter.

Also called: data build tool, dbt Core, dbt platform, dbt Cloud, dbt-bigquery, dbt Fusion

How dbt works

A dbt project is a folder of models: each .sql file is one SELECT. Instead of hardcoding table names, models reference each other with {{ ref('model_name') }} and raw tables with {{ source('app', 'events') }}. From those references dbt builds a DAG, then runs models in order and creates each one as a view, table, incremental table, ephemeral CTE or materialized view, according to its materialized config. Data tests (unique, not_null, relationships, custom SQL) run after builds, and dbt docs generates documentation with lineage.

dbt itself doesn't process data: it compiles Jinja and SQL and sends the queries to the warehouse, so BigQuery does the work and the bill shows up there.

dbt on BigQuery

The dbt-bigquery adapter maps BigQuery features to model configs: partition_by (a field, data type and granularity), cluster_by, labels, and incremental strategies merge (the default), insert_overwrite and microbatch. An incremental model that replaces only the last three days of partitions:

{{ config(
    materialized = 'incremental',
    incremental_strategy = 'insert_overwrite',
    partition_by = {'field': 'event_date', 'data_type': 'date'},
    cluster_by = ['user_id']
) }}

SELECT
  DATE(event_ts) AS event_date,
  user_id,
  COUNT(*) AS events
FROM {{ source('app', 'events') }}
{% if is_incremental() %}
WHERE DATE(event_ts) >= DATE_SUB(CURRENT_DATE(), INTERVAL 3 DAY)
{% endif %}
GROUP BY event_date, user_id

On the first run dbt builds the whole table; afterward it overwrites only the partitions present in the new results, which keeps each run cheap and makes it safe to rerun.

Cost notes

  • Full refresh versus incremental. A large table materialized as table is rebuilt from scratch on every run. Incremental models usually cut the bytes scanned to the new partitions.
  • Views are recomputed on read. A view over heavy logic costs compute every time a dashboard queries it; materialize hot models.
  • Label your jobs. Use query-comment with job-label: true so BigQuery jobs carry model metadata for cost attribution.
  • Schedule by need. Hourly runs of models read once a day multiply cost without benefit, and models nobody reads are dead-end tables.

Common pitfalls

  • is_incremental() filters that use CURRENT_DATE() make reruns of past days impossible without a full refresh; use variables for backfills.
  • merge without unique_key behaves as an append and duplicates rows on rerun.
  • Tests that scan whole large tables on every run can cost more than the models they check; limit them to recent partitions.

FAQ

What is the difference between dbt Core and the dbt platform?

dbt Core is the open-source command-line tool that compiles and runs a dbt project. The dbt platform (formerly dbt Cloud) is dbt Labs' managed service around it, with a browser IDE, scheduling, CI and hosted documentation.

dbt or Dataform on BigQuery?

Both turn SQL files into BigQuery tables with dependencies, tests and incremental models. Dataform is a free Google Cloud service built into BigQuery; dbt runs on many warehouses and has a larger package ecosystem. See the dbt vs Dataform comparison linked on this page.

How do I label dbt jobs in BigQuery for cost tracking?

The labels model config labels the table, not the job. To label jobs, set query-comment with job-label: true in dbt_project.yml; dbt then adds the query comment's key-value pairs to each job as labels.

Read next

Browse the full glossary

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.