Skip to content
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
61 changes: 61 additions & 0 deletions macros/tests/sequence_distinct_gaps_buffered_look_back.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% macro sequence_distinct_gaps_buffered_look_back(
table,
partition_by,
column,
delayed_column,
delayed_period
) %}
{%- set partition_sql = partition_by | join(", ") -%}
{%- set previous_column = "prev_" ~ column -%}
WITH source AS (
SELECT
{{ partition_sql + "," if partition_sql }}
{{ column }},
LAG(
{{ column }},
1
) over (
{{ "PARTITION BY " ~ partition_sql if partition_sql }}
ORDER BY
{{ column }} ASC
) AS {{ previous_column }},
LAG(
{{ delayed_column }},
1
) over (
{{ "PARTITION BY " ~ partition_sql if partition_sql }}
ORDER BY
{{ column }} ASC
) AS {{ delayed_column }}
FROM
(
SELECT
DISTINCT {{ column }},
MAX(
{{ delayed_column }}
) AS {{ delayed_column }}
FROM
{{ table }}
GROUP BY
{{ column }}
)
)
SELECT
{{ partition_sql + "," if partition_sql }}
{{ previous_column }},
{{ column }},
{{ column }} - {{ previous_column }}
- 1 AS gap
FROM
source
WHERE
{{ column }} - {{ previous_column }} <> 1
AND {{ delayed_column }} < (
SELECT
MAX(
{{ delayed_column }}
)
FROM
{{ this }}
) - INTERVAL '{{ delayed_period }}'
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ sequence_distinct_gaps_buffered_look_back(ref('silver_algorand__transactions'), [], "block_id", "_inserted_timestamp", "15 HOURS") }}