diff --git a/.changes/2.5.0.md b/.changes/2.5.0.md new file mode 100644 index 0000000..9d6009b --- /dev/null +++ b/.changes/2.5.0.md @@ -0,0 +1,7 @@ +## dbt-snowflake-query-tags 2.5.0 - May 15, 2024 + +### Features + +- Support custom extra kwarg for query tag meta ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f66b0d..b38cea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). +## dbt-snowflake-query-tags 2.5.0 - May 15, 2024 + +### Features + +- Support custom extra kwarg for query tag meta ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) + + + ## dbt-snowflake-query-tags 2.4.1 - May 14, 2024 ### Fixes diff --git a/README.md b/README.md index 3a8bed9..1398fee 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,12 @@ That's it! All dbt-issued queries will now be tagged. ### Query comments +#### Meta and tag model configs + Both [meta](https://docs.getdbt.com/reference/resource-configs/meta) and [tag](https://docs.getdbt.com/reference/resource-configs/tags) configs are automatically added to the query comments. +#### 'extra' kwarg + To add arbitrary keys and values to the comments, you can use the `extra` kwarg when calling `dbt_snowflake_query_tags.get_query_comment`. For example, to add a `run_started_at` key and value to the comment, we can do: ```yaml @@ -179,6 +183,24 @@ Results in a final query tag of '{"team": "data", "job_name": "daily", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.2", "is_incremental": true}' ``` +#### 'extra' kwarg + +Like the query comment macro, the query tag macro also supports an 'extra' kwarg. To make use of it, you'll need to configure this package following the dbt < 1.2 instructions. Then you can add any logic you like for additional query tag metadata in `query_tags.sql`. + +``` +{% macro set_query_tag() -%} + {% do return(dbt_snowflake_query_tags.set_query_tag( + extra={ + 'custom_config_property': config.get('custom_config_property'), + } + )) %} +{% endmacro %} + +{% macro unset_query_tag(original_query_tag) -%} + {% do return(dbt_snowflake_query_tags.unset_query_tag(original_query_tag)) %} +{% endmacro %} +``` + ## Contributing ### Adding a CHANGELOG Entry diff --git a/dbt_project.yml b/dbt_project.yml index 46405bd..4547cc7 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,3 +1,3 @@ name: 'dbt_snowflake_query_tags' -version: '2.4.1' +version: '2.5.0' config-version: 2 diff --git a/macros/query_comment.sql b/macros/query_comment.sql index 3842df9..0797061 100644 --- a/macros/query_comment.sql +++ b/macros/query_comment.sql @@ -2,7 +2,7 @@ {%- set comment_dict = extra -%} {%- do comment_dict.update( app='dbt', - dbt_snowflake_query_tags_version='2.4.1', + dbt_snowflake_query_tags_version='2.5.0', dbt_version=dbt_version, project_name=project_name, target_name=target.name, diff --git a/macros/query_tags.sql b/macros/query_tags.sql index 1030d90..d3d3d80 100644 --- a/macros/query_tags.sql +++ b/macros/query_tags.sql @@ -1,8 +1,8 @@ -{% macro set_query_tag() -%} - {{ return(adapter.dispatch('set_query_tag', 'dbt_snowflake_query_tags')()) }} +{% macro set_query_tag(extra = {}) -%} + {{ return(adapter.dispatch('set_query_tag', 'dbt_snowflake_query_tags')(extra=extra)) }} {%- endmacro %} -{% macro default__set_query_tag() -%} +{% macro default__set_query_tag(extra = {}) -%} {# Get session level query tag #} {% set original_query_tag = get_current_query_tag() %} {% set original_query_tag_parsed = {} %} @@ -32,10 +32,11 @@ {% do query_tag.update(original_query_tag_parsed) %} {% do query_tag.update(env_var_query_tags) %} + {% do query_tag.update(extra) %} {%- do query_tag.update( app='dbt', - dbt_snowflake_query_tags_version='2.4.1', + dbt_snowflake_query_tags_version='2.5.0', ) -%} {% if thread_id %}