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

Creating new generic tests for redshift adapter #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions dbt/include/redshift/macros/generic_test_sql/accepted_values.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% macro redshift__test_accepted_values(model, column_name, values, quote=True) %}

with all_values as (

select
"{{ column_name }}" as value_field,
count(*) as n_records

from {{ model }}
group by "{{ column_name }}"

)

select *
from all_values
where value_field not in (
{% for value in values -%}
{% if quote -%}
'{{ value }}'
{%- else -%}
{{ value }}
{%- endif -%}
{%- if not loop.last -%},{%- endif %}
{%- endfor %}
)

{% endmacro %}
10 changes: 10 additions & 0 deletions dbt/include/redshift/macros/generic_test_sql/not_null.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro redshift__test_not_null(model, column_name) %}

{% set column_name = '"' ~ column_name ~ '"'%}
{% set column_list = '*' if should_store_failures() else column_name %}

select {{ column_list }}
from {{ model }}
where {{ column_name }} is null

{% endmacro %}
23 changes: 23 additions & 0 deletions dbt/include/redshift/macros/generic_test_sql/relationships.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro redshift__test_relationships(model, column_name, to, field) %}

with child as (
select "{{ column_name }}" as from_field
from {{ model }}
where "{{ column_name }}" is not null
),

parent as (
select {{ field }} as to_field
from {{ to }}
)

select
from_field

from child
left join parent
on child.from_field = parent.to_field

where parent.to_field is null

{% endmacro %}
12 changes: 12 additions & 0 deletions dbt/include/redshift/macros/generic_test_sql/unique.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro redshift__test_unique(model, column_name) %}

select
"{{ column_name }}" as unique_field,
count(*) as n_records

from {{ model }}
where "{{ column_name }}" is not null
group by "{{ column_name }}"
having count(*) > 1

{% endmacro %}