forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnot_constant.sql
More file actions
27 lines (17 loc) · 753 Bytes
/
not_constant.sql
File metadata and controls
27 lines (17 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{% test not_constant(model, column_name, group_by_columns = []) %}
{{ return(adapter.dispatch('test_not_constant', 'dbt_utils')(model, column_name, group_by_columns)) }}
{% endtest %}
{% macro default__test_not_constant(model, column_name, group_by_columns) %}
{% if group_by_columns|length() > 0 %}
{% set select_gb_cols = group_by_columns|join(' ,') + ', ' %}
{% set groupby_gb_cols = 'group by ' + group_by_columns|join(',') %}
{% endif %}
select
{# In TSQL, subquery aggregate columns need aliases #}
{# thus: a filler col name, 'filler_column' #}
{{select_gb_cols}}
count(distinct {{ column_name }}) as filler_column
from {{ model }}
{{groupby_gb_cols}}
having count(distinct {{ column_name }}) = 1
{% endmacro %}