-
Notifications
You must be signed in to change notification settings - Fork 510
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 #161 from MartinGuindon/feature/relationships_where
Add a new schema test: relationships_where
- Loading branch information
Showing
5 changed files
with
89 additions
and
4 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
4 changes: 4 additions & 0 deletions
4
integration_tests/data/schema_tests/data_test_relationships_where_table_1.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,4 @@ | ||
id | ||
1 | ||
2 | ||
3 |
4 changes: 4 additions & 0 deletions
4
integration_tests/data/schema_tests/data_test_relationships_where_table_2.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,4 @@ | ||
id | ||
1 | ||
2 | ||
4 |
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,48 @@ | ||
{% macro test_relationships_where(model, to, field) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %} | ||
{% set from_condition = kwargs.get('from_condition', "true") %} | ||
{% set to_condition = kwargs.get('to_condition', "true") %} | ||
|
||
with left_table as ( | ||
|
||
select | ||
{{column_name}} as id | ||
|
||
from {{model}} | ||
|
||
where {{column_name}} is not null | ||
and {{from_condition}} | ||
|
||
), | ||
|
||
right_table as ( | ||
|
||
select | ||
{{field}} as id | ||
|
||
from {{to}} | ||
|
||
where {{field}} is not null | ||
and {{to_condition}} | ||
|
||
), | ||
|
||
exceptions as ( | ||
|
||
select | ||
left_table.id, | ||
right_table.id as right_id | ||
|
||
from left_table | ||
|
||
left join right_table | ||
on left_table.id = right_table.id | ||
|
||
where right_table.id is null | ||
|
||
) | ||
|
||
select count(*) from exceptions | ||
|
||
{% endmacro %} |