Migrating a dbt Pipeline from PostgreSQL to BigQuery: What Changes and What Doesn’t
Summary
A technical account details the migration of a dbt pipeline, originally built on local PostgreSQL for NYC Taxi and Olist datasets, to Google BigQuery. This transition addresses PostgreSQL's limitations in production, such as lack of team accessibility, scalable partitioning, and managed infrastructure. Key changes involved adapting SQL dialect, specifically "CAST" syntax and "EXTRACT(DAYOFWEEK)" functions, and reconfiguring "profiles.yml" for BigQuery's OAuth and service account authentication. New implementations included partitioning by "pickup_datetime" and clustering by "trip_id" for cost optimization, alongside a 3-day lookback window for incremental models. Furthermore, a CI/CD pipeline was established using GitHub Actions, automating 18 dbt tests on every push to the main branch, secured by a dedicated service account with minimal permissions. The core dbt model structure, business logic, and incremental model concepts remained warehouse-agnostic.
Key takeaway
For Data Engineers migrating dbt pipelines to cloud data warehouses like BigQuery, you must account for significant SQL dialect differences and authentication changes beyond just "profiles.yml". Implement BigQuery's native partitioning and clustering on relevant columns, such as "pickup_datetime" and "trip_id", to optimize query costs. Additionally, establish a robust CI/CD pipeline with GitHub Actions and dedicated service accounts to automate data quality checks and ensure production readiness.
Key insights
Migrating dbt pipelines to cloud warehouses requires adapting SQL dialects, authentication, and implementing cloud-native optimizations.
Principles
- BigQuery charges by data scanned, not query time.
- CI/CD automates data quality gates.
- dbt models can be warehouse-agnostic by design.
Method
Migrate dbt by adapting SQL dialect, configuring "profiles.yml" for cloud authentication, implementing partitioning/clustering, and setting up CI/CD with service accounts and GitHub Secrets.
In practice
- Use "CAST(column AS TYPE)" for BigQuery type casting.
- Partition by date and cluster by ID for BigQuery cost savings.
- Implement a 3-day lookback for incremental models.
Topics
- dbt
- BigQuery
- PostgreSQL
- Data Migration
- CI/CD
- GitHub Actions
- Data Engineering
Code references
Best for: Data Engineer, MLOps Engineer
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by Data Engineering on Medium.