-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1614 from fishtown-analytics/fix/snapshot-check-c…
…ols-cycle possible fix for re-used check cols on BQ
- Loading branch information
Showing
7 changed files
with
205 additions
and
35 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
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
9 changes: 6 additions & 3 deletions
9
plugins/bigquery/dbt/include/bigquery/macros/materializations/snapshot.sql
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
51 changes: 51 additions & 0 deletions
51
...ration/004_simple_snapshot_test/check-snapshots-expected/check_snapshots_test_current.sql
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,51 @@ | ||
|
||
|
||
with query as ( | ||
|
||
-- check that the current value for id=1 is red | ||
select case when ( | ||
select count(*) | ||
from {{ ref('check_cols_cycle') }} | ||
where id = 1 and color = 'red' and dbt_valid_to is null | ||
) = 1 then 0 else 1 end as failures | ||
|
||
union all | ||
|
||
-- check that the previous 'red' value for id=1 is invalidated | ||
select case when ( | ||
select count(*) | ||
from {{ ref('check_cols_cycle') }} | ||
where id = 1 and color = 'red' and dbt_valid_to is not null | ||
) = 1 then 0 else 1 end as failures | ||
|
||
union all | ||
|
||
-- check that there's only one current record for id=2 | ||
select case when ( | ||
select count(*) | ||
from {{ ref('check_cols_cycle') }} | ||
where id = 2 and color = 'pink' and dbt_valid_to is null | ||
) = 1 then 0 else 1 end as failures | ||
|
||
union all | ||
|
||
-- check that the previous value for id=2 is represented | ||
select case when ( | ||
select count(*) | ||
from {{ ref('check_cols_cycle') }} | ||
where id = 2 and color = 'green' and dbt_valid_to is not null | ||
) = 1 then 0 else 1 end as failures | ||
|
||
union all | ||
|
||
-- check that there are 5 records total in the table | ||
select case when ( | ||
select count(*) | ||
from {{ ref('check_cols_cycle') }} | ||
) = 5 then 0 else 1 end as failures | ||
|
||
) | ||
|
||
select * | ||
from query | ||
where failures = 1 |
33 changes: 33 additions & 0 deletions
33
test/integration/004_simple_snapshot_test/check-snapshots/check_cols_cycle.sql
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,33 @@ | ||
|
||
{% snapshot check_cols_cycle %} | ||
|
||
{{ | ||
config( | ||
target_database=database, | ||
target_schema=schema, | ||
unique_key='id', | ||
strategy='check', | ||
check_cols=['color'] | ||
) | ||
}} | ||
|
||
{% if var('version') == 1 %} | ||
|
||
select 1 as id, 'red' as color union all | ||
select 2 as id, 'green' as color | ||
|
||
{% elif var('version') == 2 %} | ||
|
||
select 1 as id, 'blue' as color union all | ||
select 2 as id, 'green' as color | ||
|
||
{% elif var('version') == 3 %} | ||
|
||
select 1 as id, 'red' as color union all | ||
select 2 as id, 'pink' as color | ||
|
||
{% else %} | ||
{% do exceptions.raise_compiler_error("Got bad version: " ~ var('version')) %} | ||
{% endif %} | ||
|
||
{% endsnapshot %} |
55 changes: 55 additions & 0 deletions
55
test/integration/004_simple_snapshot_test/test_snapshot_check_cols.py
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,55 @@ | ||
from test.integration.base import DBTIntegrationTest, use_profile | ||
import dbt.exceptions | ||
|
||
|
||
class TestSimpleSnapshotFiles(DBTIntegrationTest): | ||
NUM_SNAPSHOT_MODELS = 1 | ||
|
||
@property | ||
def schema(self): | ||
return "simple_snapshot_004" | ||
|
||
@property | ||
def models(self): | ||
return "models" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"snapshot-paths": ['check-snapshots'], | ||
"test-paths": ['check-snapshots-expected'], | ||
"source-paths": [], | ||
} | ||
|
||
def test_snapshot_check_cols_cycle(self): | ||
results = self.run_dbt(["snapshot", '--vars', 'version: 1']) | ||
self.assertEqual(len(results), 1) | ||
|
||
results = self.run_dbt(["snapshot", '--vars', 'version: 2']) | ||
self.assertEqual(len(results), 1) | ||
|
||
results = self.run_dbt(["snapshot", '--vars', 'version: 3']) | ||
self.assertEqual(len(results), 1) | ||
|
||
def assert_expected(self): | ||
self.run_dbt(['test', '--data', '--vars', 'version: 3']) | ||
|
||
@use_profile('snowflake') | ||
def test__snowflake__simple_snapshot(self): | ||
self.test_snapshot_check_cols_cycle() | ||
self.assert_expected() | ||
|
||
@use_profile('postgres') | ||
def test__postgres__simple_snapshot(self): | ||
self.test_snapshot_check_cols_cycle() | ||
self.assert_expected() | ||
|
||
@use_profile('bigquery') | ||
def test__bigquery__simple_snapshot(self): | ||
self.test_snapshot_check_cols_cycle() | ||
self.assert_expected() | ||
|
||
@use_profile('redshift') | ||
def test__redshift__simple_snapshot(self): | ||
self.test_snapshot_check_cols_cycle() | ||
self.assert_expected() |