-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enablement due to dbt-utils' "dispatchifiction" #17
Changes from all commits
e68b95c
41547e2
4cfc406
cb788d7
6f205e3
96e29db
f47fb18
31151a0
1aeb356
72f422f
a37e6c8
47711de
9c43f6b
4230be2
008ba9c
270e953
37449a9
50811e8
88a4beb
80ca9b7
fff18d3
74f9d84
6eb5af3
a274666
04c9234
f46b793
f92d4b5
0217691
49c41a3
9449055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro sqlserver__limit_zero() %} | ||
{{ return('where 0=1') }} | ||
{% endmacro %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% macro sqlserver__hash(field) %} | ||
hashbytes('md5', {{field}}) | ||
convert(varchar(50), hashbytes('md5', {{field}}), 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @swanderz just noting that this will limit hashable field size to 50 (bytes not chars I think). Is this intended behaviour? Could use string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at this as well. I had the same in the old sqlserver-utils package. Maybe we can have varchar(max)? Most cases will be hashing one column, but if you want to look for diffs, like watching for changes, you may include a lot of columns making the hashes longer then 50 |
||
{% endmacro %} | ||
|
||
|
||
|
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, | ||
dataders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
-- 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 | ||
dataders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 %} |
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 %} |
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 %} |
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 %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this may result in changes in dbt-utils breaking things on our side without an explicit commit as not pegged to a certain version.