From 898433fcc2927d218da4b1405d3d2d3554c67617 Mon Sep 17 00:00:00 2001 From: joshuao11 Date: Fri, 8 Nov 2024 14:57:58 +0000 Subject: [PATCH 1/2] Drop temp table if exists The insert overwrite does this, so let's copy that pattern here to keep the schemas/datasets tidy in BQ for the users --- .../materializations/incremental_strategy/merge.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql b/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql index a204caed9..091f7cd91 100644 --- a/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql +++ b/dbt/include/bigquery/macros/materializations/incremental_strategy/merge.sql @@ -27,8 +27,12 @@ {% do predicates.append(avoid_require_partition_filter) %} {%- endif -%} - {% set build_sql = get_merge_sql(target_relation, source_sql, unique_key, dest_columns, predicates) %} + -- 1. Run merge statement + {{ get_merge_sql(target_relation, source_sql, unique_key, dest_columns, predicates) }}; - {{ return(build_sql) }} + {% if tmp_relation_exists -%} + -- 2. clean up the temp table if we have used one + drop table if exists {{ tmp_relation }}; + {%- endif -%} {% endmacro %} From 647544d2c4b35922bcbf46f7b65be1e069811014 Mon Sep 17 00:00:00 2001 From: joshuao11 Date: Fri, 8 Nov 2024 15:46:38 +0000 Subject: [PATCH 2/2] Generated by Changie --- .changes/unreleased/Fixes-20241108-154557.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241108-154557.yaml diff --git a/.changes/unreleased/Fixes-20241108-154557.yaml b/.changes/unreleased/Fixes-20241108-154557.yaml new file mode 100644 index 000000000..0bc3c9622 --- /dev/null +++ b/.changes/unreleased/Fixes-20241108-154557.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Cleans up the temp table created by the merge incremental stratergy when checking the schema +time: 2024-11-08T15:45:57.570611Z +custom: + Author: joshuao11 + Issue: "1389"