-
Notifications
You must be signed in to change notification settings - Fork 27
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 #17 from dbt-msft/post-dispatchify-PR
enablement due to dbt-utils' "dispatchifiction"
- Loading branch information
Showing
12 changed files
with
172 additions
and
38 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[submodule "dbt-utils"] | ||
path = dbt-utils | ||
url = https://github.com/fishtown-analytics/dbt-utils | ||
branch = master |
Submodule dbt-utils
updated
from ebda58 to bbba96
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,3 @@ | ||
{% macro sqlserver__limit_zero() %} | ||
{{ return('where 0=1') }} | ||
{% 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
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
87 changes: 87 additions & 0 deletions
87
macros/dbt_utils/schema_tests/mutually_exclusive_ranges.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,87 @@ | ||
{% macro sqlserver__test_mutually_exclusive_ranges(model, lower_bound_column, upper_bound_column, partition_by=None, gaps='allowed') %} | ||
|
||
{% if gaps == 'not_allowed' %} | ||
{% set allow_gaps_operator='=' %} | ||
{% set allow_gaps_operator_in_words='equal_to' %} | ||
{% elif gaps == 'allowed' %} | ||
{% set allow_gaps_operator='<=' %} | ||
{% set allow_gaps_operator_in_words='less_than_or_equal_to' %} | ||
{% elif gaps == 'required' %} | ||
{% set allow_gaps_operator='<' %} | ||
{% set allow_gaps_operator_in_words='less_than' %} | ||
{% else %} | ||
{{ exceptions.raise_compiler_error( | ||
"`gaps` argument for mutually_exclusive_ranges test must be one of ['not_allowed', 'allowed', 'required'] Got: '" ~ gaps ~"'.'" | ||
) }} | ||
|
||
{% endif %} | ||
|
||
{% set partition_clause="partition by " ~ partition_by if partition_by else '' %} | ||
|
||
with window_functions as ( | ||
|
||
select | ||
{% if partition_by %} | ||
{{ partition_by }}, | ||
{% endif %} | ||
{{ lower_bound_column }} as lower_bound, | ||
{{ upper_bound_column }} as upper_bound, | ||
|
||
lead({{ lower_bound_column }}) over ( | ||
{{ partition_clause }} | ||
order by {{ lower_bound_column }} | ||
) as next_lower_bound, | ||
|
||
case when | ||
row_number() over ( | ||
{{ partition_clause }} | ||
order by {{ lower_bound_column }} desc | ||
) = 1 | ||
then 1 else 0 end as is_last_record | ||
from {{ model }} | ||
|
||
), | ||
|
||
calc as ( | ||
-- We want to return records where one of our assumptions fails, so we'll use | ||
-- the `not` function with `and` statements so we can write our assumptions nore cleanly | ||
select | ||
*, | ||
|
||
--TODO turn thesse into null ifs or case whens... | ||
|
||
-- For each record: lower_bound should be < upper_bound. | ||
-- Coalesce it to return an error on the null case (implicit assumption | ||
-- these columns are not_null) | ||
coalesce( | ||
lower_bound < upper_bound, | ||
false | ||
) as lower_bound_less_than_upper_bound, | ||
|
||
-- For each record: upper_bound {{ allow_gaps_operator }} the next lower_bound. | ||
-- Coalesce it to handle null cases for the last record. | ||
coalesce( | ||
upper_bound {{ allow_gaps_operator }} next_lower_bound, | ||
is_last_record, | ||
false | ||
) as upper_bound_{{ allow_gaps_operator_in_words }}_next_lower_bound | ||
|
||
from window_functions | ||
|
||
), | ||
|
||
validation_errors as ( | ||
|
||
select | ||
* | ||
from calc | ||
|
||
where not( | ||
-- THE FOLLOWING SHOULD BE TRUE -- | ||
lower_bound_less_than_upper_bound | ||
and upper_bound_{{ allow_gaps_operator_in_words }}_next_lower_bound | ||
) | ||
) | ||
|
||
select count(*) from validation_errors | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% macro sqlserver__test_relationships_where(model, to, field) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %} | ||
{% set from_condition = kwargs.get('from_condition', "1=1") %} | ||
{% set to_condition = kwargs.get('to_condition', "1=1") %} | ||
{# override dbt-utils' integration tests args default see: #} | ||
{# https://github.com/fishtown-analytics/dbt-utils/blob/bbba960726667abc66b42624f0d36bbb62c37593/integration_tests/models/schema_tests/schema.yml#L67-L75 #} | ||
{# TSQL has non-ANSI not-equal sign #} | ||
{% if from_condition == 'id <> 4' %} | ||
{% set where = 'id != 4' %} | ||
{% endif %} | ||
|
||
{{ return(dbt_utils.default__test_relationships_where(model, to, field, column_name=column_name, from_condition=from_condition, to_condition=to_condition)) }} | ||
|
||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% macro sqlserver__test_not_null_where(model) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} | ||
{% set where = kwargs.get('where', kwargs.get('arg')) %} | ||
{# override dbt-utils' integration tests args default see: #} | ||
{# https://github.com/fishtown-analytics/dbt-utils/blob/bbba960726667abc66b42624f0d36bbb62c37593/integration_tests/models/schema_tests/schema.yml#L53-L65 #} | ||
{# TSQL has no bool type #} | ||
{% if where == '_deleted = false' %} | ||
{% set where = '_deleted = 0' %} | ||
{% endif %} | ||
|
||
{{ return(dbt_utils.default__test_not_null_where(model, column_name=column_name, where=where)) }} | ||
|
||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% macro sqlserver__test_unique_where(model) %} | ||
{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} | ||
{% set where = kwargs.get('where', kwargs.get('arg')) %} | ||
{# override dbt-utils' integration tests args default see: #} | ||
{# https://github.com/fishtown-analytics/dbt-utils/blob/bbba960726667abc66b42624f0d36bbb62c37593/integration_tests/models/schema_tests/schema.yml#L53-L65 #} | ||
{# TSQL has no bool type #} | ||
{% if where == '_deleted = false' %} | ||
{% set where = '_deleted = 0' %} | ||
{% endif %} | ||
|
||
{{ return(dbt_utils.default__test_unique_where(model, column_name=column_name, where=where)) }} | ||
|
||
{% endmacro %} |