-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix snapshot config to work in yaml files (#10275)
- Loading branch information
Showing
8 changed files
with
120 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Fix snapshot config to work in yaml files | ||
time: 2024-06-07T13:46:48.383215-04:00 | ||
custom: | ||
Author: gshank | ||
Issue: "4000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import run_dbt, write_file | ||
|
||
orders_sql = """ | ||
select 1 as id, 101 as user_id, 'pending' as status | ||
""" | ||
|
||
snapshot_sql = """ | ||
{% snapshot orders_snapshot %} | ||
{{ | ||
config( | ||
target_schema=schema, | ||
strategy='check', | ||
unique_key='id', | ||
check_cols=['status'], | ||
) | ||
}} | ||
select * from {{ ref('orders') }} | ||
{% endsnapshot %} | ||
""" | ||
|
||
snapshot_no_config_sql = """ | ||
{% snapshot orders_snapshot %} | ||
select * from {{ ref('orders') }} | ||
{% endsnapshot %} | ||
""" | ||
|
||
snapshot_schema_yml = """ | ||
snapshots: | ||
- name: orders_snapshot | ||
config: | ||
target_schema: test | ||
strategy: check | ||
unique_key: id | ||
check_cols: ['status'] | ||
""" | ||
|
||
|
||
class TestSnapshotConfig: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"orders.sql": orders_sql} | ||
|
||
@pytest.fixture(scope="class") | ||
def snapshots(self): | ||
return {"snapshot_orders.sql": snapshot_sql} | ||
|
||
def test_config(self, project): | ||
run_dbt(["run"]) | ||
results = run_dbt(["snapshot"]) | ||
assert len(results) == 1 | ||
|
||
# try to parse with config in schema file | ||
write_file( | ||
snapshot_no_config_sql, project.project_root, "snapshots", "snapshot_orders.sql" | ||
) | ||
write_file(snapshot_schema_yml, project.project_root, "snapshots", "snapshot.yml") | ||
results = run_dbt(["parse"]) | ||
|
||
results = run_dbt(["snapshot"]) | ||
assert len(results) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters