Skip to content

Commit

Permalink
Support quoted column names in sequential_values test (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandduijn committed Feb 18, 2022
1 parent 8b7356b commit 14127aa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions macros/schema_tests/sequential_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

{% macro default__test_sequential_values(model, column_name, interval=1, datepart=None) %}

{% set previous_column_name = "previous_" ~ dbt_utils.slugify(column_name) %}

with windowed as (

select
{{ column_name }},
lag({{ column_name }}) over (
order by {{ column_name }}
) as previous_{{ column_name }}
) as {{ previous_column_name }}
from {{ model }}
),

Expand All @@ -21,9 +23,9 @@ validation_errors as (
*
from windowed
{% if datepart %}
where not(cast({{ column_name }} as {{ dbt_utils.type_timestamp() }})= cast({{ dbt_utils.dateadd(datepart, interval, 'previous_' + column_name) }} as {{ dbt_utils.type_timestamp() }}))
where not(cast({{ column_name }} as {{ dbt_utils.type_timestamp() }})= cast({{ dbt_utils.dateadd(datepart, interval, previous_column_name) }} as {{ dbt_utils.type_timestamp() }}))
{% else %}
where not({{ column_name }} = previous_{{ column_name }} + {{ interval }})
where not({{ column_name }} = {{ previous_column_name }} + {{ interval }})
{% endif %}
)

Expand Down

0 comments on commit 14127aa

Please sign in to comment.