Skip to content

Commit 418278c

Browse files
committed
t-sql hacks that shouldn't break mainline behavior
1 parent ebda584 commit 418278c

5 files changed

+13
-10
lines changed

macros/schema_tests/at_least_one.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
select count(*)
66
from (
77
select
8-
9-
count({{ column_name }})
8+
{# subquery aggregate columns need aliases #}
9+
{# thus: 'unique_values' #}
10+
count({{ column_name }}) as unique_values
1011

1112
from {{ model }}
1213

macros/schema_tests/cardinality_equality.sql

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% macro test_cardinality_equality(model, to, field) %}
2-
2+
{# T-SQL doesn't let you use numbers as aliases for columns #}
3+
{# Thus, no "GROUP BY 1" #}
34
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %}
45

56

@@ -8,15 +9,15 @@ select
89
{{ column_name }},
910
count(*) as num_rows
1011
from {{ model }}
11-
group by 1
12+
group by {{ column_name }}
1213
),
1314

1415
table_b as (
1516
select
1617
{{ field }},
1718
count(*) as num_rows
1819
from {{ to }}
19-
group by 1
20+
group by {{ column_name }}
2021
),
2122

2223
except_a as (

macros/schema_tests/expression_is_true.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{% macro test_expression_is_true(model, condition='true') %}
2-
1+
{% macro test_expression_is_true(model, condition='1=1') %}
2+
{# T-SQL has no boolean data type so we use 1=1 which returns TRUE #}
3+
{# ref https://stackoverflow.com/a/7170753/3842610 #}
34
{% set expression = kwargs.get('expression', kwargs.get('arg')) %}
45

56
with meet_condition as (

macros/schema_tests/not_constant.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ select count(*)
88
from (
99

1010
select
11-
count(distinct {{ column_name }})
11+
count(distinct {{ column_name }}) as filler_column
1212

1313
from {{ model }}
1414

macros/schema_tests/relationships_where.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% macro test_relationships_where(model, to, field) %}
22

33
{% set column_name = kwargs.get('column_name', kwargs.get('from')) %}
4-
{% set from_condition = kwargs.get('from_condition', "true") %}
5-
{% set to_condition = kwargs.get('to_condition', "true") %}
4+
{% set from_condition = kwargs.get('from_condition', "1=1") %}
5+
{% set to_condition = kwargs.get('to_condition', "1=1") %}
66

77
with left_table as (
88

0 commit comments

Comments
 (0)