Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Exclude sessions after cutoff time from starting_number
Browse files Browse the repository at this point in the history
  • Loading branch information
clrcrl authored Feb 6, 2019
2 parents 9dd189f + 00fe820 commit 0c0dffd
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
dist = 'session_id'
)}}

{% set sessionization_cutoff = "
(
select
dateadd(
hour,
-{{var('segment_sessionization_trailing_window')}},
max(session_start_tstamp)
)
from {{this}}
)
" %}

{#
Window functions are challenging to make incremental. This approach grabs
Expand All @@ -28,15 +39,7 @@ with sessions as (
select * from {{ref('segment_web_sessions__stitched')}}

{% if is_incremental() %}
where session_start_tstamp > (
select {{
dbt_utils.safe_cast(
dbt_utils.dateadd(
'hour',
-var('segment_sessionization_trailing_window'),
'max(session_start_tstamp)'),
'timestamp') }}
from {{this}})
where session_start_tstamp > {{sessionization_cutoff}}
{% endif %}

),
Expand All @@ -49,6 +52,10 @@ agg as (
blended_user_id,
count(*) as starting_session_number
from {{this}}

-- only include sessions that are not going to be resessionized in this run
where session_start_tstamp <= {{sessionization_cutoff}}

group by 1

),
Expand Down

0 comments on commit 0c0dffd

Please sign in to comment.