Skip to content

Commit

Permalink
Merge pull request dbt-labs#77 from fishtown-analytics/macros-v2
Browse files Browse the repository at this point in the history
Add support for schema.yml version 2
  • Loading branch information
beckjake authored Sep 4, 2018
2 parents 7469d67 + eb34e0c commit c82b0bf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
8 changes: 5 additions & 3 deletions macros/schema_tests/at_least_one.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{% macro test_at_least_one(model, arg) %}
{% macro test_at_least_one(model) %}

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

select count(*)
from (
select

count({{ arg }})
count({{ column_name }})

from {{ model }}

having count({{ arg }}) = 0
having count({{ column_name }}) = 0

) validation_errors

Expand Down
6 changes: 4 additions & 2 deletions macros/schema_tests/cardinality_equality.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% macro test_cardinality_equality(model, from, to, field) %}
{% macro test_cardinality_equality(model, to, field) %}

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

with table_a as (
select
{{ from }},
{{ column_name }},
count(*) as num_rows
from {{ model }}
group by 1
Expand Down
6 changes: 4 additions & 2 deletions macros/schema_tests/equality.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% macro test_equality(model, arg) %}
{% macro test_equality(model) %}

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


{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
Expand Down Expand Up @@ -26,7 +28,7 @@ with a as (

b as (

select * from {{ arg }}
select * from {{ compare_model }}

),

Expand Down
8 changes: 5 additions & 3 deletions macros/schema_tests/not_constant.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

{% macro test_not_constant(model, arg) %}
{% macro test_not_constant(model) %}

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

select count(*)

from (

select
count(distinct {{ arg }})
count(distinct {{ column_name }})

from {{ model }}

having count(distinct {{ arg }}) = 1
having count(distinct {{ column_name }}) = 1

) validation_errors

Expand Down
6 changes: 4 additions & 2 deletions macros/schema_tests/recency.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% macro test_recency(model, field, datepart, interval) %}
{% macro test_recency(model, datepart, interval) %}

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

select
case when count(*) > 0 then 0
else 1
end as error_result
from {{model}}
where {{field}} >=
where {{column_name}} >=
{{dbt_utils.dateadd(datepart, interval * -1, dbt_utils.current_timestamp())}}

{% endmacro %}

0 comments on commit c82b0bf

Please sign in to comment.