|
4 | 4 |
|
5 | 5 | {% macro default__set_query_tag() -%}
|
6 | 6 | {# Start with any model-configured dict #}
|
7 |
| - {% set tag_dict = config.get('query_tag', default={}) %} |
| 7 | + {% set query_tag = config.get('query_tag', default={}) %} |
8 | 8 |
|
9 |
| - {%- do tag_dict.update( |
| 9 | + {% if query_tag is not mapping %} |
| 10 | + {% do log("dbt-snowflake-query-tags warning: the query_tag config value of '{}' is not a mapping type, so is being ignored. If you'd like to add additional query tag information, use a mapping type instead, or remove it to avoid this message.".format(query_tag), True) %} |
| 11 | + {% set query_tag = {} %} {# If the user has set the query tag config as a non mapping type, start fresh #} |
| 12 | + {% endif %} |
| 13 | + |
| 14 | + |
| 15 | + {%- do query_tag.update( |
10 | 16 | app='dbt',
|
11 | 17 | dbt_snowflake_query_tags_version='2.3.0',
|
12 | 18 | ) -%}
|
13 | 19 |
|
14 | 20 | {% if thread_id %}
|
15 |
| - {%- do tag_dict.update( |
| 21 | + {%- do query_tag.update( |
16 | 22 | thread_id=thread_id
|
17 | 23 | ) -%}
|
18 | 24 | {% endif %}
|
19 | 25 |
|
20 | 26 |
|
21 | 27 | {# We have to bring is_incremental through here because its not available in the comment context #}
|
22 | 28 | {% if model.resource_type == 'model' %}
|
23 |
| - {%- do tag_dict.update( |
| 29 | + {%- do query_tag.update( |
24 | 30 | is_incremental=is_incremental()
|
25 | 31 | ) -%}
|
26 | 32 | {% endif %}
|
27 | 33 |
|
28 |
| - {% set new_query_tag = tojson(tag_dict) %} |
| 34 | + {% set query_tag_json = tojson(query_tag) %} |
29 | 35 | {% set original_query_tag = get_current_query_tag() %}
|
30 |
| - {{ log("Setting query_tag to '" ~ new_query_tag ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }} |
31 |
| - {% do run_query("alter session set query_tag = '{}'".format(new_query_tag)) %} |
| 36 | + {{ log("Setting query_tag to '" ~ query_tag_json ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }} |
| 37 | + {% do run_query("alter session set query_tag = '{}'".format(query_tag_json)) %} |
32 | 38 | {{ return(original_query_tag)}}
|
33 | 39 | {% endmacro %}
|
34 | 40 |
|
|
0 commit comments