Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE - change schema destination of __dbt_tmp tables #1444

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20250108-204100.yaml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 13 additions & 1 deletion dbt/include/bigquery/macros/materializations/incremental.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%}
Expand Down
Loading