-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seems like these unfortunately need to be duplicated for now. DBT assumes they are under tests/generic
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- this tests checks a model for every row in a seed file. | ||
-- you need to specify the matching columns and the columns to check for equality. | ||
-- filter: dictionary filter of column:value that is applied to the seed file | ||
-- actual implementation in macros/test-helpers/check_seed.sql | ||
{% test check_seed(model, seed_file, match_columns=[], check_columns=[], filter=None) %} | ||
{# | ||
--jinja comment | ||
-- potential dynamic approach, but requires db access -- ci setup to allow in future? | ||
-- {%- set unique_columns = config.get('unique_key') -%} | ||
-- {%- set seed_check_columns = dbt_utils.get_filtered_columns_in_relation(from=seed_file, except=unique_columns) -%} | ||
-- {%- set seed_matching_columns = dbt_utils.get_filtered_columns_in_relation(from=seed_file, except=seed_check_columns) -%} | ||
--jinja comment | ||
#} | ||
{{ config(severity = 'error') }} | ||
{%- set seed_check_columns = check_columns -%} | ||
{%- set seed_matching_columns = match_columns -%} | ||
{%- set seed = seed_file -%} | ||
{{ check_seed_macro(model,seed,seed_matching_columns,seed_check_columns,filter) }} | ||
|
||
{% endtest %} |
22 changes: 22 additions & 0 deletions
22
daily_spellbook/tests/generic/compare_column_values_to_seed_values.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,22 @@ | ||
{% test compare_column_values_to_seed_values(model, column_name, seed_file_location) %} | ||
|
||
with unit_test as | ||
( | ||
select | ||
seed.test_description, | ||
case | ||
when m.{{ column_name }} = seed.{{ column_name }} | ||
then True | ||
else False | ||
end as generic_column_test | ||
from {{ model }} m | ||
join {{ seed_file_location }} seed | ||
on m.tx_hash = seed.tx_hash | ||
and m.block_number = seed.block_number | ||
) | ||
|
||
select test_description | ||
from unit_test | ||
where generic_column_test = False | ||
|
||
{% endtest %} |
27 changes: 27 additions & 0 deletions
27
daily_spellbook/tests/generic/equal_rowcount_with_sources.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,27 @@ | ||
{% test equal_rowcount_with_sources(model, evt_sources=[]) %} | ||
|
||
WITH | ||
model_count as ( | ||
select count(*) as count_a from {{ model }} | ||
) | ||
,sources_count as ( | ||
select sum(count_b) as count_b | ||
from ( | ||
{% for source in evt_sources %} | ||
select count(*) as count_b | ||
from {{ source }} | ||
where evt_block_time <= (select max(block_time) from {{ model }}) | ||
{% if not loop.last %} UNION ALL {% endif %} | ||
{% endfor %} | ||
) b | ||
) | ||
|
||
,unit_test as ( | ||
select count_a, count_b, abs(count_a - count_b) as diff_count | ||
from model_count | ||
full outer join sources_count | ||
on 1=1 | ||
) | ||
|
||
select * from unit_test where diff_count > 0 | ||
{% endtest %} |
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 @@ | ||
{% test is_unique_filtered(model, column_name) %} | ||
|
||
select | ||
{{ column_name }} as unique_field, | ||
count(*) as n_records | ||
|
||
from {{ model }} | ||
where {{ column_name }} is not null | ||
and block_date >= NOW() - interval '2' day | ||
group by {{ column_name }} | ||
having count(*) > 1 | ||
|
||
{% endtest %} |