Skip to content

feat(ol_dbt_cli): add ol-dbt local snapshot and raw-relation support to ol-dbt diff #2469

Open
rachellougee wants to merge 3 commits into
mainfrom
feat/ol-dbt-diff-glue-relations-and-snapshot
Open

feat(ol_dbt_cli): add ol-dbt local snapshot and raw-relation support to ol-dbt diff #2469
rachellougee wants to merge 3 commits into
mainfrom
feat/ol-dbt-diff-glue-relations-and-snapshot

Conversation

@rachellougee

@rachellougee rachellougee commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

#2407

Description (What does it do?)

Adds a new companion command for local dbt development, plus support in ol-dbt diff for comparing against it:

  • ol-dbt local snapshot: save a model's current build under a new name, so you can easily compare it against itself before and after a code change.
  • ol-dbt diff --old-raw/--new-raw (plus --old-schema/--new-schema/--old-database/--new-database): compare against an already-materialized table — like a snapshot, or a copy sitting in another schema/database — instead of only a live dbt model.

Useful for validating and fixing bugs in how a report joins its dimensional tables — used to find and fix the remaining bugs in enrollment_detail_report see #2468

Test plan

How can this be tested?

Verifies ol-dbt local snapshot + ol-dbt diff --old-raw correctly isolate a code change from production drift

  1. cd src/ol_dbt
  2. Register a model's Glue tables and build it locally:
ol-dbt local setup    # one-time bootstrap for the local DuckDB+Iceberg dev environment                                                                                                   
ol-dbt local register --database ol_warehouse_production_dimensional                                                                                           
ol-dbt run --select dim_user --target dev_local        
  1. Snapshot the current build as a frozen baseline: ol-dbt local snapshot dim_user --as dim_user_baseline
  2. With no code change yet, diff the baseline against the live model — should show a clean match, confirming the round trip is precise:
    ol-dbt diff --target dev_local --old dim_user_baseline --old-raw --new dim_user --primary-key user_pk
  3. Expected: MATCH ... row Δ 0, 0 column mismatch(es).
  4. Make a real code change to dim_user.sql, then rebuild: ol-dbt run --select dim_user --target dev_local
  5. Re-run the same diff from step 4 — any mismatch now reported is attributable only to the code change, since both sides are built from the same underlying data pull.
  Verified real output (step 4, no change made):                                                                                                                 
  MATCH  dim_user_baseline (raw) → dim_user  (dev_local)                                                                                                         
     Compared columns: 48                                                                                                                                        
     Row counts: dim_user_baseline (raw)=7549738  dim_user=7549738  Δ=0                                                                                          
  Summary: match — row Δ 0, 0 column mismatch(es).                                                                                                               

Additional Context

…nd local snapshot command

- ol-dbt diff --old-glue/--new-glue compares a local build against the
  real, already-materialized production table via its Glue-registered
  view, without requiring a rebuild of that side. --new now defaults to
  --old's value for this common case. --refresh-glue re-registers Glue
  views first, since production rebuilds regularly invalidate previously
  registered ones (stale S3 metadata 404s).
- Fixes discovered along the way: a silently-swallowed dbt error in raw
  column resolution, a double-LIMIT DuckDB parser error, a long-standing
  f-string brace-escaping bug that broke every per-column comparison
  with a primary key, and an IcebergScan/UNION-ALL limitation worked
  around by materializing the glue-registered side into a real table
  before comparing.
- Narrows per-column comparison queries to primary key + compared column
  instead of selecting every column, and reformats sample mismatches to
  show only the differing fields per key instead of full-row JSON dumps.
- New `ol-dbt local snapshot` command copies a model's current build
  into a plain table under a new name, for before/after comparisons of
  the same model across a code change without involving Glue/production.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔎 ol-dbt impact — column-level blast radius

✅ No column-level downstream impact detected for the changed models.

Posted by ol-dbt impact (annotate-only — does not block merge).

@rachellougee rachellougee changed the title feat(ol_dbt_cli): diff against Glue-registered views, add local snapshot command feat(ol_dbt_cli): add ol-dbt local snapshot and raw-relation support to ol-dbt diff Jul 22, 2026
@rachellougee
rachellougee marked this pull request as ready for review July 22, 2026 18:29
Copilot AI review requested due to automatic review settings July 22, 2026 18:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds local-development tooling to make dbt model changes easier to validate by enabling “before/after” baselines and allowing ol-dbt diff to compare against already-materialized relations (not only manifest-resolved ref() models). This supports safer dimensional/mart migrations by making row/column-level comparisons against production-derived data practical and repeatable.

Changes:

  • Add ol-dbt local snapshot to materialize a model’s current build under a new table name for baseline comparisons.
  • Extend ol-dbt diff with --old-raw/--new-raw plus schema/database overrides to diff against literal relations, and improve mismatch output formatting.
  • Expand CLI documentation and tests to cover snapshotting, raw relation resolution, and labeling/output behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ol_dbt/README.md Documents workflows for using ol-dbt diff together with ol-dbt local snapshot, including raw-relation comparisons across schemas.
src/ol_dbt_cli/ol_dbt_cli/commands/local_dev.py Adds the local snapshot command that CTAS-copies a model build to a baseline table.
src/ol_dbt_cli/ol_dbt_cli/commands/diff.py Adds raw-relation support (Relation.create), schema/database overrides, improved per-column query generation, and clearer mismatch formatting/labels.
src/ol_dbt_cli/tests/test_local_dev.py Adds unit tests validating snapshot SQL construction and identifier validation.
src/ol_dbt_cli/tests/test_diff.py Adds extensive coverage for raw relation handling, relation Jinja rendering, sample mismatch formatting, labels, and JSON schema updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ol_dbt_cli/ol_dbt_cli/commands/local_dev.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants