From 6f1df6ae6544015e3a3a7c648db7f13a47408209 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Mon, 18 Nov 2019 14:57:56 -0500 Subject: [PATCH 1/2] Fix for drop statement which was not namespaced to a schema --- .../materializations/incremental/incremental.sql | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/dbt/include/global_project/macros/materializations/incremental/incremental.sql b/core/dbt/include/global_project/macros/materializations/incremental/incremental.sql index 4a06ac476ca..7ac4a2ae289 100644 --- a/core/dbt/include/global_project/macros/materializations/incremental/incremental.sql +++ b/core/dbt/include/global_project/macros/materializations/incremental/incremental.sql @@ -8,10 +8,6 @@ {% set existing_relation = load_relation(this) %} {% set tmp_relation = make_temp_relation(this) %} - {# -- set the type so our rename / drop uses the correct syntax #} - {% set backup_type = existing_relation.type | default("table") %} - {% set backup_relation = make_temp_relation(this, "__dbt_backup").incorporate(type=backup_type) %} - {{ run_hooks(pre_hooks, inside_transaction=False) }} -- `BEGIN` happens here: @@ -21,6 +17,11 @@ {% if existing_relation is none %} {% set build_sql = create_table_as(False, target_relation, sql) %} {% elif existing_relation.is_view or full_refresh_mode %} + {#-- Make sure the backup doesn't exist so we don't encounter issues with the rename below #} + {% set backup_identifier = existing_relation.identifier ~ "__dbt_backup" %} + {% set backup_relation = existing_relation.incorporate(path={"identifier": backup_identifier}) %} + {% do adapter.drop_relation(backup_relation) %} + {% do adapter.rename_relation(target_relation, backup_relation) %} {% set build_sql = create_table_as(False, target_relation, sql) %} {% do to_drop.append(backup_relation) %} @@ -43,7 +44,7 @@ {% do adapter.commit() %} {% for rel in to_drop %} - {% do drop_relation(rel) %} + {% do adapter.drop_relation(rel) %} {% endfor %} {{ run_hooks(post_hooks, inside_transaction=False) }} From ba111db2a8d5d72f84efb9c41c621200988c0023 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Mon, 18 Nov 2019 16:06:20 -0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1bba18cb60..b6bf6b6bdd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Improve CLI output when running snapshots ([#1768](https://github.com/fishtown-analytics/dbt/issues/1768), [#1769](https://github.com/fishtown-analytics/dbt/pull/1769)) #### Fixes +- Fix for lingering backup tables when incremental models are full-refreshed ([#1933](https://github.com/fishtown-analytics/dbt/issues/1933), [#1931](https://github.com/fishtown-analytics/dbt/pull/1931)) - Fix for confusing error message when errors are encountered during compilation ([#1807](https://github.com/fishtown-analytics/dbt/issues/1807), [#1839](https://github.com/fishtown-analytics/dbt/pull/1839)) - Fix for logic error affecting the two-argument flavor of the `ref` function ([#1504](https://github.com/fishtown-analytics/dbt/issues/1504), [#1515](https://github.com/fishtown-analytics/dbt/pull/1515)) - Fix for invalid reference to dbt.exceptions ([#1569](https://github.com/fishtown-analytics/dbt/issues/1569), [#1609](https://github.com/fishtown-analytics/dbt/pull/1609))