From d2c678973004644503e22ee09ed2c3b79d0df4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20V=C3=A1zquez-Barreiros?= Date: Wed, 8 Jan 2025 20:41:08 +0000 Subject: [PATCH] changing destination Update incremental.sql --- .changes/unreleased/Features-20250108-204100.yaml | 6 ++++++ .../bigquery/macros/materializations/incremental.sql | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Features-20250108-204100.yaml diff --git a/.changes/unreleased/Features-20250108-204100.yaml b/.changes/unreleased/Features-20250108-204100.yaml new file mode 100644 index 000000000..0e17005fa --- /dev/null +++ b/.changes/unreleased/Features-20250108-204100.yaml @@ -0,0 +1,6 @@ +kind: Features +body: allow changing the schema destination of tmp tables +time: 2025-01-08T20:41:00.190868Z +custom: + Author: borjavb + Issue: "1443" diff --git a/dbt/include/bigquery/macros/materializations/incremental.sql b/dbt/include/bigquery/macros/materializations/incremental.sql index 25a83b0c6..58014fade 100644 --- a/dbt/include/bigquery/macros/materializations/incremental.sql +++ b/dbt/include/bigquery/macros/materializations/incremental.sql @@ -72,12 +72,20 @@ {% materialization incremental, adapter='bigquery', supported_languages=['sql', 'python'] -%} {%- set unique_key = config.get('unique_key') -%} + {%- set temp_schema = config.get('temp_schema') -%} {%- set full_refresh_mode = (should_full_refresh()) -%} {%- set language = model['language'] %} {%- set target_relation = this %} {%- set existing_relation = load_relation(this) %} - {%- set tmp_relation = make_temp_relation(this) %} + {%- set temp_schema = config.get('temp_schema') -%} + {%- if temp_schema is not none-%} + {%- set temp_relation = this.incorporate(path={ + "schema": temp_schema + }) -%} + {%- do create_schema(temp_relation) -%} + {% endif %} + {%- set tmp_relation = make_temp_relation(temp_relation) %} {#-- Validate early so we don't run SQL if the strategy is invalid --#} {% set strategy = dbt_bigquery_validate_get_incremental_strategy(config) -%}