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 #7 from fishtown-analytics/refactor/incremental-mo…
Browse files Browse the repository at this point in the history
…del-updates

Use is_incremental macro. Remove sql_where
  • Loading branch information
clrcrl authored Feb 4, 2019
2 parents ddf851f + 2584950 commit 28cc150
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

{{ config(
materialized = 'incremental',
sql_where = 'TRUE',
unique_key = 'page_view_id',
sort = 'tstamp',
dist = 'page_view_id'
Expand All @@ -28,7 +27,7 @@ with pageviews as (
select * from {{ref('segment_web_page_views')}}
{% if adapter.already_exists(this.schema, this.table) and not flags.FULL_REFRESH %}
{% if is_incremental() %}
where anonymous_id in (
select distinct anonymous_id
from {{ref('segment_web_page_views')}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

{{ config(
materialized = 'incremental',
sql_where = 'TRUE',
unique_key = 'session_id',
sort = 'session_start_tstamp',
dist = 'session_id'
)}}

{% set incremental = adapter.already_exists(this.schema, this.table) and not flags.FULL_REFRESH %}

{#
Window functions are challenging to make incremental. This approach grabs
Expand All @@ -29,7 +27,7 @@ with sessions as (

select * from {{ref('segment_web_sessions__stitched')}}

{% if incremental %}
{% if is_incremental() %}
where session_start_tstamp > (
select
dateadd(
Expand All @@ -42,7 +40,7 @@ with sessions as (

),

{% if incremental %}
{% if is_incremental() %}

agg as (

Expand Down Expand Up @@ -71,8 +69,8 @@ windowed as (

from sessions

{% if incremental %}
left join agg using (blended_user_id)
{% if is_incremental() %}
{% endif %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

{{ config(
materialized = 'incremental',
sql_where = 'TRUE',
unique_key = 'session_id',
sort = 'session_start_tstamp',
dist = 'session_id'
Expand Down Expand Up @@ -51,7 +50,7 @@ with pageviews as (

select * from {{ref('segment_web_page_views__sessionized')}}

{% if adapter.already_exists(this.schema, this.table) and not flags.FULL_REFRESH %}
{% if is_incremental() %}
where tstamp > (select dateadd(hour, -{{var('segment_sessionization_trailing_window')}}, max(session_start_tstamp)) from {{this}})
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

{{ config(
materialized = 'incremental',
sql_where = 'TRUE',
unique_key = 'session_id',
sort = 'session_start_tstamp',
dist = 'session_id'
Expand All @@ -19,7 +18,7 @@ with sessions as (

select * from {{ref('segment_web_sessions__initial')}}

{% if adapter.already_exists(this.schema, this.table) and not flags.FULL_REFRESH %}
{% if is_incremental() %}
where session_start_tstamp > (select dateadd(hour, -{{var('segment_sessionization_trailing_window')}}, max(session_start_tstamp)) from {{this}})
{% endif %}

Expand Down

0 comments on commit 28cc150

Please sign in to comment.