-
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.
- Loading branch information
Showing
27 changed files
with
258 additions
and
30 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
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
44 changes: 40 additions & 4 deletions
44
core/dbt/include/global_project/macros/materializations/test.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 |
---|---|---|
@@ -1,10 +1,46 @@ | ||
{%- materialization test, default -%} | ||
|
||
{% set relations = [] %} | ||
|
||
{% if flags.STORE_FAILURES %} | ||
|
||
{% set identifier = model['name'] %} | ||
{% set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %} | ||
{% set target_relation = api.Relation.create( | ||
identifier=identifier, schema=schema, database=database, type='table') -%} %} | ||
|
||
{% if old_relation %} | ||
{% do adapter.drop_relation(old_relation) %} | ||
{% endif %} | ||
|
||
{% call statement(auto_begin=True) %} | ||
{{ create_table_as(False, target_relation, sql) }} | ||
{% endcall %} | ||
|
||
{% do relations.append(target_relation) %} | ||
|
||
{% set main_sql %} | ||
select count(*) as validation_errors | ||
from {{ target_relation }} | ||
{% endset %} | ||
|
||
{{ adapter.commit() }} | ||
|
||
{% else %} | ||
|
||
{% set main_sql %} | ||
select count(*) as validation_errors | ||
from ( | ||
{{ sql }} | ||
) _dbt_internal_test | ||
{% endset %} | ||
|
||
{% endif %} | ||
|
||
{% call statement('main', fetch_result=True) -%} | ||
select count(*) as validation_errors | ||
from ( | ||
{{ sql }} | ||
) _dbt_internal_test | ||
{{ main_sql }} | ||
{%- endcall %} | ||
|
||
{{ return({'relations': relations}) }} | ||
|
||
{%- endmaterialization -%} |
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
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
11 changes: 11 additions & 0 deletions
11
test/integration/067_store_test_failures_tests/data/expected/expected_failing_test.csv
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,11 @@ | ||
id,first_name,last_name,email,gender,ip_address | ||
1,Jack,Hunter,jhunter0@pbs.org,Male,59.80.20.168 | ||
2,Kathryn,Walker,kwalker1@ezinearticles.com,Female,194.121.179.35 | ||
3,Gerald,Ryan,gryan2@com.com,Male,11.3.212.243 | ||
4,Bonnie,Spencer,bspencer3@ameblo.jp,Female,216.32.196.175 | ||
5,Harold,Taylor,htaylor4@people.com.cn,Male,253.10.246.136 | ||
6,Jacqueline,Griffin,jgriffin5@t.co,Female,16.13.192.220 | ||
7,Wanda,Arnold,warnold6@google.nl,Female,232.116.150.64 | ||
8,Craig,Ortiz,cortiz7@sciencedaily.com,Male,199.126.106.13 | ||
9,Gary,Day,gday8@nih.gov,Male,35.81.68.186 | ||
10,Rose,Wright,rwright9@yahoo.co.jp,Female,236.82.178.100 |
3 changes: 3 additions & 0 deletions
3
...on/067_store_test_failures_tests/data/expected/expected_not_null_problematic_model_id.csv
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,3 @@ | ||
id,first_name,last_name,email,gender,ip_address | ||
,Gerald,Ryan,gryan2@com.com,Male,11.3.212.243 | ||
,Bonnie,Spencer,bspencer3@ameblo.jp,Female,216.32.196.175 |
3 changes: 3 additions & 0 deletions
3
...tion/067_store_test_failures_tests/data/expected/expected_unique_problematic_model_id.csv
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,3 @@ | ||
value,num | ||
2,2 | ||
1,2 |
11 changes: 11 additions & 0 deletions
11
test/integration/067_store_test_failures_tests/data/people.csv
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,11 @@ | ||
id,first_name,last_name,email,gender,ip_address | ||
1,Jack,Hunter,jhunter0@pbs.org,Male,59.80.20.168 | ||
2,Kathryn,Walker,kwalker1@ezinearticles.com,Female,194.121.179.35 | ||
3,Gerald,Ryan,gryan2@com.com,Male,11.3.212.243 | ||
4,Bonnie,Spencer,bspencer3@ameblo.jp,Female,216.32.196.175 | ||
5,Harold,Taylor,htaylor4@people.com.cn,Male,253.10.246.136 | ||
6,Jacqueline,Griffin,jgriffin5@t.co,Female,16.13.192.220 | ||
7,Wanda,Arnold,warnold6@google.nl,Female,232.116.150.64 | ||
8,Craig,Ortiz,cortiz7@sciencedaily.com,Male,199.126.106.13 | ||
9,Gary,Day,gday8@nih.gov,Male,35.81.68.186 | ||
10,Rose,Wright,rwright9@yahoo.co.jp,Female,236.82.178.100 |
1 change: 1 addition & 0 deletions
1
test/integration/067_store_test_failures_tests/models/fine_model.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 @@ | ||
select * from {{ ref('people') }} |
11 changes: 11 additions & 0 deletions
11
test/integration/067_store_test_failures_tests/models/problematic_model.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,11 @@ | ||
select * from {{ ref('people') }} | ||
|
||
union all | ||
|
||
select * from {{ ref('people') }} | ||
where id in (1,2) | ||
|
||
union all | ||
|
||
select null as id, first_name, last_name, email, gender, ip_address from {{ ref('people') }} | ||
where id in (3,4) |
17 changes: 17 additions & 0 deletions
17
test/integration/067_store_test_failures_tests/models/schema.yml
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,17 @@ | ||
version: 2 | ||
|
||
models: | ||
|
||
- name: fine_model | ||
columns: | ||
- name: id | ||
tests: | ||
- unique | ||
- not_null | ||
|
||
- name: problematic_model | ||
columns: | ||
- name: id | ||
tests: | ||
- unique | ||
- not_null |
Oops, something went wrong.