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..3c211d4e1 100644 --- a/dbt/include/bigquery/macros/materializations/incremental.sql +++ b/dbt/include/bigquery/macros/materializations/incremental.sql @@ -69,15 +69,27 @@ {% endmacro %} + +{% macro generate_tmp_schema(base_relation, tmp_schema=none) %} + {%- if tmp_schema is not none-%} + {%- set tmp_relation = base_relation.incorporate(path={"schema": tmp_schema }) -%} + {%- do create_schema(tmp_relation) -%} + {{ return(tmp_relation) }} + {% endif %} + {{ return(base_relation) }} +{% endmacro %} + {% materialization incremental, adapter='bigquery', supported_languages=['sql', 'python'] -%} {%- set unique_key = config.get('unique_key') -%} + {%- set tmp_schema = config.get('tmp_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 tmp_set_schema = generate_tmp_schema(this, tmp_schema) -%} + {%- set tmp_relation = make_temp_relation(tmp_set_schema) %} {#-- Validate early so we don't run SQL if the strategy is invalid --#} {% set strategy = dbt_bigquery_validate_get_incremental_strategy(config) -%}