This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from dbt-labs/sessionization-incremental-dispa…
…tched Dispatch sessionization incremental filter
- Loading branch information
Showing
1 changed file
with
21 additions
and
19 deletions.
There are no files selected for viewing
40 changes: 21 additions & 19 deletions
40
macros/dbt_segment_utils.sql → ...ate_sessionization_incremental_filter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
{% macro generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %} | ||
{{ return(adapter.dispatch('generate_sessionization_incremental_filter', 'segment') (merge_target, filter_tstamp, max_tstamp)) }} | ||
{% endmacro %} | ||
|
||
{% if target.type == 'bigquery' %} | ||
where {{ filter_tstamp }} >= ( | ||
select | ||
timestamp_sub( | ||
max({{ max_tstamp }}), | ||
interval {{ var('segment_sessionization_trailing_window') }} hour | ||
) | ||
from {{ merge_target }} | ||
) | ||
|
||
{% elif target.type == 'postgres' %} | ||
where cast({{ filter_tstamp }} as timestamp) >= ( | ||
{% macro default__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %} | ||
where {{ filter_tstamp }} >= ( | ||
select | ||
{{ dbt_utils.dateadd( | ||
'hour', | ||
-var('segment_sessionization_trailing_window'), | ||
'max(' ~ max_tstamp ~ ')' | ||
) }} | ||
from {{ merge_target }} | ||
) | ||
) | ||
{%- endmacro -%} | ||
|
||
{% else %} | ||
where {{ filter_tstamp }} >= ( | ||
{% macro bigquery__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %} | ||
where {{ filter_tstamp }} >= ( | ||
select | ||
timestamp_sub( | ||
max({{ max_tstamp }}), | ||
interval {{ var('segment_sessionization_trailing_window') }} hour | ||
) | ||
from {{ merge_target }} | ||
) | ||
{%- endmacro -%} | ||
|
||
{% macro postgres__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %} | ||
where cast({{ filter_tstamp }} as timestamp) >= ( | ||
select | ||
{{ dbt_utils.dateadd( | ||
'hour', | ||
-var('segment_sessionization_trailing_window'), | ||
'max(' ~ max_tstamp ~ ')' | ||
) }} | ||
from {{ merge_target }} | ||
) | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} | ||
) | ||
{%- endmacro -%} |