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

Commit

Permalink
Merge pull request #81 from rjh336/fix/BUG-80
Browse files Browse the repository at this point in the history
Ensure proper incremental filtering + test for session_number
  • Loading branch information
joellabes authored Mar 7, 2022
2 parents fbf5c49 + d08d231 commit 2f37ff9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions macros/generate_sessionization_incremental_filter.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% 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)) }}
{% macro generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp, operator) %}
{{ return(adapter.dispatch('generate_sessionization_incremental_filter', 'segment') (merge_target, filter_tstamp, max_tstamp, operator)) }}
{% endmacro %}


{% macro default__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %}
where {{ filter_tstamp }} >= (
{% macro default__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp, operator) %}
where {{ filter_tstamp }} {{ operator }} (
select
{{ dbt_utils.dateadd(
'hour',
Expand All @@ -15,8 +15,8 @@
)
{%- endmacro -%}

{% macro bigquery__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %}
where {{ filter_tstamp }} >= (
{% macro bigquery__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp, operator) %}
where {{ filter_tstamp }} {{ operator }} (
select
timestamp_sub(
max({{ max_tstamp }}),
Expand All @@ -26,8 +26,8 @@
)
{%- endmacro -%}

{% macro postgres__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp) %}
where cast({{ filter_tstamp }} as timestamp) >= (
{% macro postgres__generate_sessionization_incremental_filter(merge_target, filter_tstamp, max_tstamp, operator) %}
where cast({{ filter_tstamp }} as timestamp) {{ operator }} (
select
{{ dbt_utils.dateadd(
'hour',
Expand Down
2 changes: 1 addition & 1 deletion models/sessionization/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ models:
description: ''
tests:
- unique
- not_null
- not_null
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ with pageviews as (
select distinct anonymous_id
from {{ref('segment_web_page_views')}}
{{
generate_sessionization_incremental_filter( this, 'tstamp', 'tstamp' )
generate_sessionization_incremental_filter( this, 'tstamp', 'tstamp', '>' )
}}
)
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions models/sessionization/segment_web_sessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with sessions as (

{% if is_incremental() %}
{{
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp' )
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp', '>' )
}}
{% endif %}

Expand All @@ -38,7 +38,7 @@ agg as (

-- only include sessions that are not going to be resessionized in this run
{{
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp' )
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp', '<=' )
}}

group by 1
Expand Down
2 changes: 1 addition & 1 deletion models/sessionization/segment_web_sessions__initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ with pageviews_sessionized as (

{% if is_incremental() %}
{{
generate_sessionization_incremental_filter( this, 'tstamp', 'session_start_tstamp' )
generate_sessionization_incremental_filter( this, 'tstamp', 'session_start_tstamp', '>' )
}}
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion models/sessionization/segment_web_sessions__stitched.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ with sessions as (

{% if is_incremental() %}
{{
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp' )
generate_sessionization_incremental_filter( this, 'session_start_tstamp', 'session_start_tstamp', '>' )
}}
{% endif %}

Expand Down

0 comments on commit 2f37ff9

Please sign in to comment.