From 16201eec3a9a485574c7b9741616fa9b1e27bce5 Mon Sep 17 00:00:00 2001 From: trouze Date: Fri, 2 Jun 2023 18:05:16 -0500 Subject: [PATCH] ct-2587: adds query tag macros and updates table materialization --- .../macros/materializations/configs.sql | 16 ++++++++++++++++ .../materializations/models/table/table.sql | 3 +++ 2 files changed, 19 insertions(+) diff --git a/core/dbt/include/global_project/macros/materializations/configs.sql b/core/dbt/include/global_project/macros/materializations/configs.sql index d15ccb8e603..c0c2704b7b1 100644 --- a/core/dbt/include/global_project/macros/materializations/configs.sql +++ b/core/dbt/include/global_project/macros/materializations/configs.sql @@ -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() %} + {{ log("Couldn't set query tag, current adapter does not have get_current_query_tag() macro implemented.",info=True) }} +{% endmacro%} + +{% macro default__unset_query_tag() %} + {{ log("Couldn't unset query tag, current adapter does not have get_current_query_tag() macro implemented.",info=True) }} +{% endmacro%} \ No newline at end of file diff --git a/core/dbt/include/global_project/macros/materializations/models/table/table.sql b/core/dbt/include/global_project/macros/materializations/models/table/table.sql index d142310addd..92267fac328 100644 --- a/core/dbt/include/global_project/macros/materializations/models/table/table.sql +++ b/core/dbt/include/global_project/macros/materializations/models/table/table.sql @@ -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) -%} @@ -55,5 +56,7 @@ {{ run_hooks(post_hooks, inside_transaction=False) }} + {% do unset_query_tag(original_query_tag) %} + {{ return({'relations': [target_relation]}) }} {% endmaterialization %}