Skip to content

Commit

Permalink
Merge pull request #128 from clausherther/fixes_insert_by_period_v013
Browse files Browse the repository at this point in the history
Upgrades insert_by_period materialization to dbt 0.13.0
  • Loading branch information
drewbanin authored Mar 26, 2019
2 parents 3616714 + 66de569 commit 083b119
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: 'dbt_utils'
version: '0.1.0'

require-dbt-version: ">=0.13.0"

target-path: "target"
clean-targets: ["target", "dbt_modules"]
macro-paths: ["macros"]
Expand Down
7 changes: 3 additions & 4 deletions macros/materializations/insert_by_period_materialization.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

{%- set identifier = model['name'] -%}

{%- set old_relation = adapter.get_relation(schema=schema, identifier=identifier) -%}
{%- set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) -%}
{%- set target_relation = api.Relation.create(identifier=identifier, schema=schema, type='table') -%}

{%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%}
Expand Down Expand Up @@ -108,7 +108,7 @@
{%- set stop_timestamp = load_result('period_boundaries')['data'][0][1] | string -%}
{%- set num_periods = load_result('period_boundaries')['data'][0][2] | int -%}

{% set target_columns = adapter.get_columns_in_table(schema, identifier) %}
{% set target_columns = adapter.get_columns_in_relation(target_relation) %}
{%- set target_cols_csv = target_columns | map(attribute='quoted') | join(', ') -%}
{%- set loop_vars = {'sum_rows_inserted': 0} -%}

Expand All @@ -132,8 +132,7 @@
{%- endcall %}

{{adapter.expand_target_column_types(temp_table=tmp_identifier,
to_schema=schema,
to_table=identifier)}}
to_relation=target_relation)}}
{%- set name = 'main-' ~ i -%}
{% call statement(name, fetch_result=True) -%}
insert into {{target_relation}} ({{target_cols_csv}})
Expand Down

0 comments on commit 083b119

Please sign in to comment.