dbt-bigquery

1.11.1 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to set up a dbt project to connect to Google BigQuery using a service account. It involves creating a `profiles.yml` file, initializing a dbt project, creating a simple SQL model, and then running dbt commands. Ensure you have a Google Cloud Project with BigQuery enabled and a service account key file.

# 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

view raw JSON →