dbt-bigquery
dbt-bigquery is the BigQuery adapter plugin for dbt (data build tool). It enables data analysts and engineers to transform their data in Google BigQuery using SQL-based models and software engineering best practices like version control, testing, and documentation. It is currently at version 1.11.1 and follows the dbt Core release cadence.
Warnings
- breaking Starting with dbt Core v1.8, installing a dbt adapter (like `dbt-bigquery`) no longer automatically installs `dbt-core`. You must explicitly install both `dbt-core` and `dbt-bigquery` to ensure a working environment.
- gotcha The `job_execution_timeout_seconds` configuration (formerly `timeout_seconds` in older versions) in `profiles.yml` is critical to prevent BigQuery queries from running indefinitely and incurring high costs. BigQuery's default behavior may not impose a strict timeout.
- gotcha BigQuery Python models and BigQuery DataFrames require additional IAM roles beyond basic BigQuery User/Data Editor, including BigQuery Job User, BigQuery Read Session User, Notebook Runtime User, Code Creator, and `colabEnterpriseUser`.
- gotcha Python 3.14 is currently not supported for `dbt-bigquery`. Users should use Python versions 3.13.x or older.
- gotcha Using `LIMIT 0` with `INSERT INTO` statements in BigQuery does not optimize the query and can still result in the scanning of the entire source table, leading to unexpected billing costs.
- deprecated With dbt Core v1.11, default warnings for non-standard YAML configurations (e.g., misspelled config keys, invalid top-level properties) are now enabled. This can expose previously overlooked issues in `dbt_project.yml` or model configurations.
Install
-
pip install dbt-core dbt-bigquery
Imports
- dbt-bigquery adapter is used via dbt CLI, not direct Python imports
dbt run
Quickstart
# Create a profiles.yml file in ~/.dbt/ or your dbt project directory.
# Ensure GCP_PROJECT_ID and GOOGLE_APPLICATION_CREDENTIALS (path to service account JSON) are set as environment variables.
# ~/.dbt/profiles.yml
# ---
# my_bigquery_project:
# target: dev
# outputs:
# dev:
# type: bigquery
# method: service-account
# project: "{{ env_var('GCP_PROJECT_ID', 'your-gcp-project-id') }}"
# dataset: "dbt_dev_dataset" # This dataset must exist in BigQuery
# keyfile: "{{ env_var('GOOGLE_APPLICATION_CREDENTIALS', 'path/to/your/service-account.json') }}"
# threads: 4
# location: US # Or your BigQuery dataset location (e.g., EU, asia-northeast1)
# job_execution_timeout_seconds: 300
# ---
# 1. Initialize a new dbt project (if you don't have one):
# dbt init my_new_dbt_project
# cd my_new_dbt_project
# 2. Edit dbt_project.yml to reference your profile (e.g., 'my_bigquery_project'):
# name: 'my_new_dbt_project'
# version: '1.0.0'
# config-version: 2
# profile: 'my_bigquery_project' # Must match a profile name in profiles.yml
# 3. Create a sample SQL model: models/my_first_model.sql
# ---
# -- models/my_first_model.sql
# SELECT
# current_timestamp() as current_time,
# 'Hello dbt-bigquery!' as message
# ---
# 4. Set environment variables (replace with your actual values):
# export GCP_PROJECT_ID="your-gcp-project-id"
# export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json"
# 5. Run dbt commands:
# dbt debug # To verify your connection to BigQuery
# dbt run # To execute the model and create a view/table in BigQuery