Skip to content

Instantly share code, notes, and snippets.

@robert8138
Last active June 8, 2020 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert8138/5c2118a0c98cb2256281aac44ccb2472 to your computer and use it in GitHub Desktop.
Save robert8138/5c2118a0c98cb2256281aac44ccb2472 to your computer and use it in GitHub Desktop.
Parameterize workflow to incorporate backfill logic
{%- if backfill %}
INSERT OVERWRITE TABLE bookings_summary PARTITION (ds)
{%- else %}
INSERT OVERWRITE TABLE bookings_summary PARTITION (ds = '{{ ds }}')
{%- endif %}
SELECT
dim_market
, SUM(m_bookings) AS m_bookings
{%- if backfill %}
, ds
{%- endif %}
FROM
fct_bookings
WHERE
{%- if backfill %}
ds BETWEEN '{{ start_date }}' AND '{{ end_date }}'
{%- else %}
ds = '{{ ds }}'
{%- endif %}
GROUP BY
dim_market
{%- if backfill %}
, ds
{%- endif %}
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment