Skip to content

Commit

Permalink
fix combine property data to drop old intraday tables
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianASchroeder authored Jul 28, 2023
1 parent 78973a2 commit 789b0a8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions macros/combine_property_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@

{% for property_id in var('property_ids') %}
{%- set schema_name = "analytics_" + property_id|string -%}
{# Copy daily tables #}
{# Copy intraday tables #}
{%- set relations = dbt_utils.get_relations_by_pattern(schema_pattern=schema_name, table_pattern='events_intraday_%', database=var('project')) -%}
{% for relation in relations %}
{%- set relation_suffix = relation.identifier|replace('events_intraday_', '') -%}
{%- if relation_suffix|int >= earliest_shard_to_retrieve|int -%}
CREATE OR REPLACE TABLE `{{var('project')}}.{{var('dataset')}}.events_intraday_{{relation_suffix}}{{property_id}}` CLONE `{{var('project')}}.analytics_{{property_id}}.events_intraday_{{relation_suffix}}`;
{%- endif -%}
{% endfor %}
{# Copy intraday tables #}
{# Copy daily tables and drop old intraday table #}
{%- set relations = dbt_utils.get_relations_by_pattern(schema_pattern=schema_name, table_pattern='events_%', exclude='events_intraday_%', database=var('project')) -%}
{% for relation in relations %}
{%- set relation_suffix = relation.identifier|replace('events_', '') -%}
{%- if relation_suffix|int >= earliest_shard_to_retrieve|int -%}
CREATE OR REPLACE TABLE `{{var('project')}}.{{var('dataset')}}.events_{{relation_suffix}}{{property_id}}` CLONE `{{var('project')}}.analytics_{{property_id}}.events_{{relation_suffix}}`;
DROP TABLE IF EXISTS `{{var('project')}}.{{var('dataset')}}.events_intraday_{{relation_suffix}}{{property_id}}`
{%- endif -%}
{% endfor %}
{% endfor %}
Expand Down

0 comments on commit 789b0a8

Please sign in to comment.