Skip to content

Commit 14127aa

Browse files
authored
Support quoted column names in sequential_values test (#479)
1 parent 8b7356b commit 14127aa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

macros/schema_tests/sequential_values.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

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

9+
{% set previous_column_name = "previous_" ~ dbt_utils.slugify(column_name) %}
10+
911
with windowed as (
1012

1113
select
1214
{{ column_name }},
1315
lag({{ column_name }}) over (
1416
order by {{ column_name }}
15-
) as previous_{{ column_name }}
17+
) as {{ previous_column_name }}
1618
from {{ model }}
1719
),
1820

@@ -21,9 +23,9 @@ validation_errors as (
2123
*
2224
from windowed
2325
{% if datepart %}
24-
where not(cast({{ column_name }} as {{ dbt_utils.type_timestamp() }})= cast({{ dbt_utils.dateadd(datepart, interval, 'previous_' + column_name) }} as {{ dbt_utils.type_timestamp() }}))
26+
where not(cast({{ column_name }} as {{ dbt_utils.type_timestamp() }})= cast({{ dbt_utils.dateadd(datepart, interval, previous_column_name) }} as {{ dbt_utils.type_timestamp() }}))
2527
{% else %}
26-
where not({{ column_name }} = previous_{{ column_name }} + {{ interval }})
28+
where not({{ column_name }} = {{ previous_column_name }} + {{ interval }})
2729
{% endif %}
2830
)
2931

0 commit comments

Comments
 (0)