Skip to content

Commit

Permalink
fix for colliding temp tables
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed May 29, 2019
1 parent f0e7e98 commit 2ef3981
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/dbt/include/global_project/macros/adapters/common.sql
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@
{{ return(load_result('check_schema_exists').table) }}
{% endmacro %}

{% macro make_temp_relation(base_relation, suffix='__dbt_tmp') %}
{{ return(adapter_macro('make_temp_relation', base_relation, suffix))}}
{% macro make_temp_relation(base_relation, suffix="__dbt_tmp") %}
{{ return(adapter_macro('make_temp_relation', base_relation, suffix)) }}
{% endmacro %}

{% macro default__make_temp_relation(base_relation, suffix) %}
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/include/global_project/macros/etc/datetime.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@
{{ return(dates_in_range(start_date, end_date, in_fmt=date_fmt)) }}
{% endmacro %}

{% macro py_current_timestring() %}
{% do return(modules.datetime.datetime.now().timestamp() | string | replace(".", "_")) %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{%- set identifier = model['alias'] -%}
{%- set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) -%}
{%- set target_relation = api.Relation.create(identifier=identifier, schema=schema, database=database, type='table') -%}
{%- set tmp_relation = make_temp_relation(target_relation, '__dbt_incremental_tmp') %}
{%- set tmp_relation = make_temp_relation(target_relation) %}

{%- set full_refresh_mode = (flags.FULL_REFRESH == True) -%}

Expand Down
2 changes: 1 addition & 1 deletion plugins/postgres/dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{%- endmacro %}

{% macro postgres__make_temp_relation(base_relation, suffix) %}
{% set tmp_identifier = base_relation.identifier ~ suffix %}
{% set tmp_identifier = base_relation.identifier ~ suffix ~ py_current_timestring() %}
{% do return(base_relation.incorporate(
table_name=tmp_identifier,
path={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
identifier=identifier,
type='table') -%}

{%- set tmp_relation = make_temp_relation(target_relation, '__dbt_tmp') %}
{%- set tmp_relation = make_temp_relation(target_relation) %}

-- setup
{{ run_hooks(pre_hooks, inside_transaction=False) }}
Expand Down

0 comments on commit 2ef3981

Please sign in to comment.