Skip to content

Commit

Permalink
t-sql hacks that shouldn't break mainline behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dataders committed Dec 23, 2020
1 parent ebda584 commit 418278c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
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

0 comments on commit 418278c

Please sign in to comment.