Skip to content

Commit

Permalink
Add set and unset query tags and update base materializations
Browse files Browse the repository at this point in the history
  • Loading branch information
trouze committed Oct 4, 2024
1 parent 10e6d59 commit 67344da
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dbt/include/global_project/macros/materializations/configs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@
{% endif %}
{% do return(config_store_failures) %}
{% endmacro %}

{% macro set_query_tag() %}
{{ return(adapter.dispatch('set_query_tag', 'dbt')()) }}
{% endmacro %}

{% macro unset_query_tag(original_query_tag) %}
{{ return(adapter.dispatch('unset_query_tag', 'dbt')(original_query_tag)) }}
{% endmacro %}

{% macro default__set_query_tag() %}
{{ return("") }}
{% endmacro%}

{% macro default__unset_query_tag() %}
{{ return("") }}
{% endmacro%}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{%- materialization clone, default -%}

{% set original_query_tag = set_query_tag() %}

{%- set relations = {'relations': []} -%}

{%- if not defer_relation -%}
Expand Down Expand Up @@ -64,4 +66,6 @@

{%- endif -%}

{% do unset_query_tag(original_query_tag) %}

{%- endmaterialization -%}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

{% materialization incremental, default -%}

{% set original_query_tag = set_query_tag() %}
-- relations
{%- set existing_relation = load_cached_relation(this) -%}
{%- set target_relation = this.incorporate(type='table') -%}
Expand Down Expand Up @@ -90,6 +91,8 @@

{{ run_hooks(post_hooks, inside_transaction=False) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}

{%- endmaterialization %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% materialization materialized_view, default %}
{% set original_query_tag = set_query_tag() %}
{% set existing_relation = load_cached_relation(this) %}
{% set target_relation = this.incorporate(type=this.MaterializedView) %}
{% set intermediate_relation = make_intermediate_relation(target_relation) %}
Expand All @@ -17,6 +18,8 @@

{{ materialized_view_teardown(backup_relation, intermediate_relation, post_hooks) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}

{% endmaterialization %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% materialization table, default %}

{% set original_query_tag = set_query_tag() %}
{%- set existing_relation = load_cached_relation(this) -%}
{%- set target_relation = this.incorporate(type='table') %}
{%- set intermediate_relation = make_intermediate_relation(target_relation) -%}
Expand Down Expand Up @@ -60,5 +61,7 @@

{{ run_hooks(post_hooks, inside_transaction=False) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}
{% endmaterialization %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{%- materialization view, default -%}

{% set original_query_tag = set_query_tag() %}
{%- set existing_relation = load_cached_relation(this) -%}
{%- set target_relation = this.incorporate(type='view') -%}
{%- set intermediate_relation = make_intermediate_relation(target_relation) -%}
Expand Down Expand Up @@ -67,6 +68,8 @@

{{ run_hooks(post_hooks, inside_transaction=False) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}

{%- endmaterialization -%}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% materialization seed, default %}

{% set original_query_tag = set_query_tag() %}
{%- set identifier = model['alias'] -%}
{%- set full_refresh_mode = (should_full_refresh()) -%}

Expand Down Expand Up @@ -55,6 +56,8 @@

{{ run_hooks(post_hooks, inside_transaction=False) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}

{% endmaterialization %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% materialization snapshot, default %}

{% set original_query_tag = set_query_tag() %}

{%- set target_table = model.get('alias', model.get('name')) -%}

{%- set strategy_name = config.get('strategy') -%}
Expand Down Expand Up @@ -102,6 +104,8 @@

{{ run_hooks(post_hooks, inside_transaction=False) }}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': [target_relation]}) }}

{% endmaterialization %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{%- materialization test, default -%}

{% set original_query_tag = set_query_tag() %}

{% set relations = [] %}

{% if should_store_failures() %}
Expand Down Expand Up @@ -55,6 +57,8 @@

{%- endcall %}

{% do unset_query_tag(original_query_tag) %}

{{ return({'relations': relations}) }}

{%- endmaterialization -%}

0 comments on commit 67344da

Please sign in to comment.