Skip to content

Commit

Permalink
date-range-backfill
Browse files Browse the repository at this point in the history
  • Loading branch information
tessa-beijloos committed May 6, 2024
1 parent 9811f8f commit b49841e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions macros/select_date_range.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro select_date_range(start_date, end_date, date_column) %}
{% if start_date is not none and end_date is not none %}
date_column >= start_date and date_column <= end_date
{% else %}
date_column >= CURRENT_DATE - var("lookback_window")
{% endif %}
{% endmacro %}
3 changes: 3 additions & 0 deletions models/staging/base/base_ga4__events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ with source as (
{{ ga4.base_select_source() }}
from {{ source('ga4', 'events') }}
where cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) >= {{var('start_date')}}
{% if end_date is not none %}
and cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) <= {{ end_date }}
{% endif %}
{% if is_incremental() %}
and parse_date('%Y%m%d', left(replace(_table_suffix, 'intraday_', ''), 8)) in ({{ partitions_to_replace | join(',') }})
{% endif %}
Expand Down

0 comments on commit b49841e

Please sign in to comment.