From 10b219e9d8e0876e0e2815e4e3144f30108dcc57 Mon Sep 17 00:00:00 2001 From: Niall Woodward Date: Thu, 18 Jan 2024 11:03:03 +0000 Subject: [PATCH 1/2] Update docs --- README.md | 18 +++++++++++++----- dbt_project.yml | 2 +- integration_test_project/dbt_project.yml | 2 +- macros/query_comment.sql | 6 +++--- macros/query_tags.sql | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 82aa4a9..205c181 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ An example query comment contains: ```json { - "dbt_snowflake_query_tags_version": "2.3.1", + "dbt_snowflake_query_tags_version": "2.3.2", "app": "dbt", "dbt_version": "1.4.0", "project_name": "my_project", @@ -45,7 +45,7 @@ Query tags are used solely for attaching the `is_incremental` flag, as this isn' ```json { - "dbt_snowflake_query_tags_version": "2.3.1", + "dbt_snowflake_query_tags_version": "2.3.2", "app": "dbt", "is_incremental": true } @@ -100,7 +100,15 @@ That's it! All dbt-issued queries will now be tagged. ### Query comments -To extend the information added in the query comments, use [meta](https://docs.getdbt.com/reference/resource-configs/meta) or [tag](https://docs.getdbt.com/reference/resource-configs/tags) configs. These are automatically added to the query comments. +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. + +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 +query-comment: + comment: '{{ dbt_snowflake_query_tags.get_query_comment(node, extra={"run_started_at": builtins.run_started_at | string }) }}' + append: true # Snowflake removes prefixed comments. +``` ### Query tags @@ -119,7 +127,7 @@ select ... Results in a final query tag of ``` -'{"team": "data", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": true}' +'{"team": "data", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.2", "is_incremental": true}' ``` the additional information is added by this package. @@ -144,7 +152,7 @@ dbt-snowflake-query-tags warning: the query_tag config value of 'data team' is n Results in a final query tag of ``` -'{"app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": false}' +'{"app": "dbt", "dbt_snowflake_query_tags_version": "2.3.2", "is_incremental": false}' ``` Note that the query_tag value of 'data team' is not present. diff --git a/dbt_project.yml b/dbt_project.yml index cce6929..8d45156 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,3 +1,3 @@ name: 'dbt_snowflake_query_tags' -version: '2.3.1' +version: '2.3.2' config-version: 2 diff --git a/integration_test_project/dbt_project.yml b/integration_test_project/dbt_project.yml index 8c69a94..ee845ef 100644 --- a/integration_test_project/dbt_project.yml +++ b/integration_test_project/dbt_project.yml @@ -13,5 +13,5 @@ dispatch: - dbt query-comment: - comment: '{{ dbt_snowflake_query_tags.get_query_comment(node) }}' + comment: '{{ dbt_snowflake_query_tags.get_query_comment(node, extra={"run_started_at": builtins.run_started_at | string }) }}' append: true # Snowflake removes prefixed comments. diff --git a/macros/query_comment.sql b/macros/query_comment.sql index cbec5ba..6d80ba3 100644 --- a/macros/query_comment.sql +++ b/macros/query_comment.sql @@ -1,8 +1,8 @@ -{% macro get_query_comment(node) %} - {%- set comment_dict = {} -%} +{% macro get_query_comment(node, extra = {}) %} + {%- set comment_dict = extra -%} {%- do comment_dict.update( app='dbt', - dbt_snowflake_query_tags_version='2.3.1', + dbt_snowflake_query_tags_version='2.3.2', 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 b9ac487..9340b75 100644 --- a/macros/query_tags.sql +++ b/macros/query_tags.sql @@ -14,7 +14,7 @@ {%- do query_tag.update( app='dbt', - dbt_snowflake_query_tags_version='2.3.1', + dbt_snowflake_query_tags_version='2.3.2', ) -%} {% if thread_id %} From 9f146faedb02322c8fb9d03995182b3a3aef3a02 Mon Sep 17 00:00:00 2001 From: Niall Woodward Date: Thu, 18 Jan 2024 11:04:44 +0000 Subject: [PATCH 2/2] Changelog --- .changes/2.3.2.md | 7 +++++++ CHANGELOG.md | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changes/2.3.2.md diff --git a/.changes/2.3.2.md b/.changes/2.3.2.md new file mode 100644 index 0000000..432fa98 --- /dev/null +++ b/.changes/2.3.2.md @@ -0,0 +1,7 @@ +## dbt-snowflake-query-tags 2.3.2 - January 18, 2024 + +### Features + +- Add support for custom query comment keys and values ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd0835..e9be45e 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.3.2 - January 18, 2024 + +### Features + +- Add support for custom query comment keys and values ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) + + + ## dbt-snowflake-query-tags 2.3.1 - August 18, 2023 ### Features