-
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 #921 from fishtown-analytics/relationships-tests-w…
…ith-nulls Relationships tests with nulls (#887)
- Loading branch information
Showing
14 changed files
with
186 additions
and
34 deletions.
There are no files selected for viewing
23 changes: 11 additions & 12 deletions
23
dbt/include/global_project/macros/schema_tests/relationships.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,19 +1,18 @@ | ||
|
||
{% macro test_relationships(model, to, from) %} | ||
{% macro test_relationships(model, to, field) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('field')) %} | ||
|
||
select count(*) | ||
from ( | ||
|
||
select | ||
{{ from }} as id | ||
|
||
from {{ model }} | ||
where {{ from }} is not null | ||
and {{ from }} not in (select {{ column_name }} | ||
from {{ to }}) | ||
|
||
) validation_errors | ||
select {{ column_name }} as id from {{ model }} | ||
) as child | ||
left join ( | ||
select {{ field }} as id from {{ to }} | ||
) as parent on parent.id = child.id | ||
where child.id is not null | ||
and parent.id is null | ||
|
||
{% endmacro %} | ||
|
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
10 changes: 10 additions & 0 deletions
10
test/integration/008_schema_tests_test/models-v1/models/table_failure_null_relation.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,10 @@ | ||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
-- force a foreign key constraint failure here | ||
select 105 as id, count(*) as count | ||
from {{ ref('table_failure_copy') }} | ||
group by 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
8 changes: 8 additions & 0 deletions
8
test/integration/008_schema_tests_test/models-v2/bq-models/ephemeral_copy.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,8 @@ | ||
|
||
{{ | ||
config( | ||
materialized='ephemeral' | ||
) | ||
}} | ||
|
||
select * from {{ this.schema }}.seed |
30 changes: 30 additions & 0 deletions
30
test/integration/008_schema_tests_test/models-v2/bq-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,30 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: ephemeral_copy | ||
description: "An ephemeral copy of the table" | ||
columns: | ||
- name: id | ||
description: "The ID" | ||
tests: | ||
- not_null | ||
- unique | ||
- name: favorite_color | ||
tests: | ||
- accepted_values: { values: ['blue', 'green'] } | ||
|
||
# this whole model should pass and run | ||
- name: table_summary | ||
description: "The summary table" | ||
columns: | ||
- name: favorite_color_copy | ||
description: "The favorite color" | ||
tests: | ||
- not_null | ||
- unique | ||
- accepted_values: { values: ['blue', 'green'] } | ||
- relationships: { field: favorite_color, to: ref('ephemeral_copy') } | ||
- name: count | ||
description: "The number of responses for this favorite color" | ||
tests: | ||
- not_null |
9 changes: 9 additions & 0 deletions
9
test/integration/008_schema_tests_test/models-v2/bq-models/table_summary.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,9 @@ | ||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
select favorite_color as favorite_color_copy, count(*) as count | ||
from {{ ref('ephemeral_copy') }} | ||
group by 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
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
10 changes: 10 additions & 0 deletions
10
test/integration/008_schema_tests_test/models-v2/models/table_failure_null_relation.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,10 @@ | ||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
-- force a foreign key constraint failure here | ||
select 105 as id, count(*) as count | ||
from {{ ref('table_failure_copy') }} | ||
group by 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
5 changes: 5 additions & 0 deletions
5
test/integration/008_schema_tests_test/models-v2/seed/seed.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,5 @@ | ||
favorite_color,id,first_name,email,ip_address,updated_at | ||
blue,1,Larry,null,69.135.206.194,2008-09-12 19:08:31 | ||
blue,2,Larry,null,64.210.133.162,1978-05-09 04:15:14 | ||
green,99,Paul,pjohnson2q@umn.edu,183.59.198.197,1991-11-14 12:33:55 | ||
green,100,Frank,fgreene2r@blogspot.com,150.143.68.121,2010-06-12 23:55:39 |
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