diff --git a/macros/generate_sessionization_incremental_filter.sql b/macros/generate_sessionization_incremental_filter.sql index 14723bf..a5498dc 100644 --- a/macros/generate_sessionization_incremental_filter.sql +++ b/macros/generate_sessionization_incremental_filter.sql @@ -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', @@ -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 }}), @@ -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', diff --git a/models/sessionization/schema.yml b/models/sessionization/schema.yml index 4600e2b..88fb204 100644 --- a/models/sessionization/schema.yml +++ b/models/sessionization/schema.yml @@ -41,4 +41,4 @@ models: description: '' tests: - unique - - not_null + - not_null \ No newline at end of file diff --git a/models/sessionization/segment_web_page_views__sessionized.sql b/models/sessionization/segment_web_page_views__sessionized.sql index 045919e..add2a5b 100644 --- a/models/sessionization/segment_web_page_views__sessionized.sql +++ b/models/sessionization/segment_web_page_views__sessionized.sql @@ -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 %} diff --git a/models/sessionization/segment_web_sessions.sql b/models/sessionization/segment_web_sessions.sql index 750f152..4fa49b0 100644 --- a/models/sessionization/segment_web_sessions.sql +++ b/models/sessionization/segment_web_sessions.sql @@ -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 %} @@ -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 diff --git a/models/sessionization/segment_web_sessions__initial.sql b/models/sessionization/segment_web_sessions__initial.sql index 163806e..02b6354 100644 --- a/models/sessionization/segment_web_sessions__initial.sql +++ b/models/sessionization/segment_web_sessions__initial.sql @@ -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 %} diff --git a/models/sessionization/segment_web_sessions__stitched.sql b/models/sessionization/segment_web_sessions__stitched.sql index 5bee687..de2771a 100644 --- a/models/sessionization/segment_web_sessions__stitched.sql +++ b/models/sessionization/segment_web_sessions__stitched.sql @@ -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 %}