Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Support individual query tag configuration for Seeds and Snapsho…
…ts (#48) * Add Query Tag for Seed * Add Query Tag for Snapshots * Add Changelog for #48 * Add Snapshot with Query Tag test * Add Seed with Query Tag test
- Loading branch information
Showing
8 changed files
with
144 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% materialization snapshot, adapter='snowflake' %} | ||
{% set original_query_tag = set_query_tag() %} | ||
|
||
{% set relations = materialization_snapshot_default() %} | ||
|
||
{% do unset_query_tag(original_query_tag) %} | ||
|
||
{{ return(relations) }} | ||
{% endmaterialization %} |
16 changes: 16 additions & 0 deletions
16
tests/integration/simple_seed_test/check-query-tag-expected/check_query_tag.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,16 @@ | ||
|
||
|
||
with query as ( | ||
|
||
-- check that the current value for id=1 is red | ||
select case when ( | ||
select count(*) | ||
from table(information_schema.query_history_by_user()) | ||
where QUERY_TAG = '{{ var('query_tag') }}' | ||
) > 1 then 0 else 1 end as failures | ||
|
||
) | ||
|
||
select * | ||
from query | ||
where failures = 1 |
41 changes: 41 additions & 0 deletions
41
tests/integration/simple_seed_test/test_seed_with_query_tag.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,41 @@ | ||
import os | ||
import csv | ||
from tests.integration.base import DBTIntegrationTest, use_profile | ||
|
||
class TestSeedWithQueryTag(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "simple_seed" | ||
|
||
@property | ||
def models(self): | ||
return "models" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
"seed-paths": ['seeds-config'], | ||
"test-paths": ['check-query-tag-expected'], | ||
'seeds': { | ||
'test': { | ||
'enabled': False, | ||
'quote_columns': True, | ||
'query_tag': self.prefix, | ||
'seed_enabled': { | ||
'enabled': True, | ||
}, | ||
}, | ||
|
||
} | ||
} | ||
|
||
def assert_query_tag_expected(self): | ||
self.run_dbt(['test', '--select', 'test_type:singular', '--vars', '{{"query_tag": {}}}'.format(self.prefix)]) | ||
|
||
@use_profile('snowflake') | ||
def test_snowflake_big_batched_seed(self): | ||
results = self.run_dbt(["seed"]) | ||
self.assertEqual(len(results), 1) | ||
self.assert_query_tag_expected() | ||
|
16 changes: 16 additions & 0 deletions
16
...s/integration/simple_snapshot_test/check-snapshots-query-tag-expected/check_query_tag.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,16 @@ | ||
|
||
|
||
with query as ( | ||
|
||
-- check that the current value for id=1 is red | ||
select case when ( | ||
select count(*) | ||
from table(information_schema.query_history_by_user()) | ||
where QUERY_TAG = '{{ var('query_tag') }}' | ||
) > 1 then 0 else 1 end as failures | ||
|
||
) | ||
|
||
select * | ||
from query | ||
where failures = 1 |
13 changes: 13 additions & 0 deletions
13
tests/integration/simple_snapshot_test/check-snapshots-query-tag/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% snapshot snapshot_query_tag %} | ||
{{ | ||
config( | ||
target_database=database, | ||
target_schema=schema, | ||
unique_key='id', | ||
strategy='check', | ||
check_cols=['color'], | ||
query_tag=var('query_tag') | ||
) | ||
}} | ||
select * from {{target.database}}.{{schema}}.seed | ||
{% endsnapshot %} |
34 changes: 34 additions & 0 deletions
34
tests/integration/simple_snapshot_test/test_snapshot_query_tag.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,34 @@ | ||
from tests.integration.base import DBTIntegrationTest, use_profile | ||
|
||
class TestSnapshotWithQueryTag(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "simple_snapshot_004" | ||
|
||
@property | ||
def models(self): | ||
return "models" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
"snapshot-paths": ['check-snapshots-query-tag'], | ||
"test-paths": ['check-snapshots-query-tag-expected'], | ||
"model-paths": [], | ||
} | ||
|
||
def dbt_run_seed(self): | ||
self.run_sql_file('seed.sql') | ||
|
||
def test_snapshot_with_query_tag(self): | ||
self.run_dbt(["snapshot", "--vars", '{{"query_tag": {}}}'.format(self.prefix)]) | ||
|
||
def assert_query_tag_expected(self): | ||
self.run_dbt(['test', '--select', 'test_type:singular', '--vars', '{{"query_tag": {}}}'.format(self.prefix)]) | ||
|
||
@use_profile('snowflake') | ||
def test__snowflake__snapshot_with_query_tag(self): | ||
self.dbt_run_seed() | ||
self.test_snapshot_with_query_tag() | ||
self.assert_query_tag_expected() |