Learn DBT + BiqQuery
README.md

try-dbt-bq #

Learning dbt with BigQuery using public datasets.

Project Structure #

models/ecommerce/stg_users.sql - A staging view that:

  • Pulls user data from BigQuery's public thelook_ecommerce dataset
  • Calculates days_since_signup for each user
  • Materializes as a view (fast, always fresh)

models/ecommerce/user_segments.sql - An analytics table that:

  • References the staging model using {{ ref('stg_users') }}
  • Segments users into: new, active, returning, veteran
  • Groups ages into brackets for analysis
  • Materializes as a table (slower to build, fast to query)

models/ecommerce/schema.yml - Documentation with:

  • Column descriptions
  • Data quality tests (uniqueness, not_null, accepted_values)

Key dbt Concepts #

  1. Models = SELECT statements that become tables/views

  2. Refs = {{ ref('model_name') }} creates dependencies between models

  3. Materialization = How dbt builds the model:

    • view - just a SQL view (no data stored)
    • table - actual table with data
    • incremental - only process new/changed data
    • ephemeral - CTE that gets inlined
  4. Tests = Data quality checks run with dbt test

Usage #

# Run all models
uv run dbt run

# Run specific model
uv run dbt run --select user_segments

# Run tests
uv run dbt test

# Generate and serve documentation
uv run dbt docs generate
uv run dbt docs serve

Setup #

This project uses:

  • dbt-bigquery for data transformations
  • BigQuery public datasets (bigquery-public-data.thelook_ecommerce.*)
  • Application Default Credentials for authentication

Authentication was set up using:

gcloud auth application-default login

Next Steps #

Explore more by:

  • Adding order/product models from the same public dataset
  • Creating metrics (total revenue, orders per user, etc.)
  • Building a DAG with multiple layers (staging → intermediate → marts)