Skip to content

Instantly share code, notes, and snippets.

@robert8138
Last active February 6, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert8138/73451dd1913f99d0ae454c322402210a to your computer and use it in GitHub Desktop.
Save robert8138/73451dd1913f99d0ae454c322402210a to your computer and use it in GitHub Desktop.
Dynamic Partitions Start
INSERT OVERWRITE TABLE bookings_summary PARTITION (ds= '{{ earliest_ds }}')
SELECT
dim_market
, SUM(m_bookings) AS m_bookings
FROM
fct_bookings
WHERE
ds = '{{ earliest_ds }}'
GROUP BY
dim_market
;
# after many insertions from '{{ earliest_ds + 1 day }}' to '{{ latest_ds - 1 day }}'
INSERT OVERWRITE TABLE bookings_summary PARTITION (ds= '{{ latest_ds }}')
SELECT
dim_market
, SUM(m_bookings) AS m_bookings
FROM
fct_bookings
WHERE
ds = '{{ latest_ds }}'
GROUP BY
dim_market
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment