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

t-sql hacks that shouldn't break mainline behavior #310

Merged
merged 10 commits into from
Jan 11, 2021
5 changes: 3 additions & 2 deletions macros/schema_tests/at_least_one.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
select count(*)
from (
select

count({{ column_name }})
{# subquery aggregate columns need aliases #}
{# thus: 'unique_values' #}
count({{ column_name }}) as unique_values

from {{ model }}

Expand Down
7 changes: 4 additions & 3 deletions macros/schema_tests/cardinality_equality.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% macro 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 All @@ -8,15 +9,15 @@ select
{{ column_name }},
count(*) as num_rows
from {{ model }}
group by 1
group by {{ column_name }}
),

table_b as (
select
{{ field }},
count(*) as num_rows
from {{ to }}
group by 1
group by {{ column_name }}
),

except_a as (
Expand Down
5 changes: 3 additions & 2 deletions macros/schema_tests/expression_is_true.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% macro test_expression_is_true(model, condition='true') %}

{% macro 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')) %}

with meet_condition as (
Expand Down
2 changes: 1 addition & 1 deletion macros/schema_tests/not_constant.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ select count(*)
from (

select
count(distinct {{ column_name }})
count(distinct {{ column_name }}) as filler_column

from {{ model }}

Expand Down
4 changes: 2 additions & 2 deletions macros/schema_tests/relationships_where.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% 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") %}
{% set from_condition = kwargs.get('from_condition', "1=1") %}
{% set to_condition = kwargs.get('to_condition', "1=1") %}

with left_table as (

Expand Down