Skip to content
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

Merged
merged 30 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e68b95c
dbt-utils macros now support dispatch
dataders Jan 6, 2021
41547e2
fix this test as well
dataders Jan 6, 2021
4cfc406
TEMP move to theoretical branch
dataders Jan 7, 2021
cb788d7
shorten list of broken macros
dataders Jan 7, 2021
6f205e3
must be string for comparison
dataders Jan 7, 2021
96e29db
synapse does not yet support
dataders Jan 7, 2021
f47fb18
fixed by dbt-util dispatchification
dataders Jan 7, 2021
31151a0
synapse does not support
dataders Jan 7, 2021
1aeb356
clean up
dataders Jan 7, 2021
72f422f
downstream fix
dataders Jan 7, 2021
a37e6c8
update submodule
dataders Jan 7, 2021
47711de
WHY PYTHON WHY!!!
dataders Jan 7, 2021
9c43f6b
inform users why
dataders Jan 8, 2021
4230be2
disable until #18 is finished
dataders Jan 8, 2021
008ba9c
unsupported
dataders Jan 8, 2021
270e953
synapse does not support timestamp
dataders Jan 8, 2021
37449a9
replacement for 'limit 0'
dataders Jan 8, 2021
50811e8
hail mary
dataders Jan 8, 2021
88a4beb
add limit zero to dispatch namespace
dataders Jan 8, 2021
80ca9b7
disabled due to other issue
dataders Jan 8, 2021
fff18d3
correct macro directory
dataders Jan 10, 2021
74f9d84
wrong section
dataders Jan 11, 2021
6eb5af3
changes are in dbt-utils now!
dataders Jan 11, 2021
a274666
pull from master w/ new PRs merged
dataders Jan 11, 2021
04c9234
perhaps these work now
dataders Jan 11, 2021
f46b793
still unported
dataders Jan 11, 2021
f92d4b5
Merge branch 'master' of https://github.com/dbt-msft/tsql-utils into …
dataders Jan 12, 2021
0217691
dbt-utils default arg is now TSQL compatible
dataders Jan 12, 2021
49c41a3
more context
dataders Jan 14, 2021
9449055
pin to latest release
dataders Jan 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion macros/dbt_utils/schema_tests/at_least_one.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro test_at_least_one(model) %}
{% macro sqlserver__test_at_least_one(model) %}

{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %}

Expand Down
2 changes: 1 addition & 1 deletion macros/dbt_utils/schema_tests/cardinality_equality.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro test_cardinality_equality(model, to, field) %}
{% macro sqlserver__test_cardinality_equality(model, to, field) %}
{# T-SQL doesn't let you use numbers as aliases for columns #}
{# Thus, no "GROUP BY 1" #}
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %}
Expand Down
2 changes: 1 addition & 1 deletion macros/dbt_utils/schema_tests/expression_is_true.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro test_expression_is_true(model, condition='1=1') %}
{% macro sqlserver__test_expression_is_true(model, condition='1=1') %}
{# T-SQL has no boolean data type so we use 1=1 which returns TRUE #}
{# ref https://stackoverflow.com/a/7170753/3842610 #}
{% set expression = kwargs.get('expression', kwargs.get('arg')) %}
Expand Down
87 changes: 87 additions & 0 deletions macros/dbt_utils/schema_tests/mutually_exclusive_ranges.sql
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 %}
2 changes: 1 addition & 1 deletion macros/dbt_utils/schema_tests/not_constant.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{% macro test_not_constant(model) %}
{% macro sqlserver__test_not_constant(model) %}

{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %}

Expand Down