Skip to content

Commit c5f7b7e

Browse files
authored
Merge pull request #18 from get-select/handle_non_mappings_gracefully
Handle non mappings gracefully
2 parents 630b422 + 1ff81b2 commit c5f7b7e

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ An example query comment contains:
66

77
```json
88
{
9-
"dbt_snowflake_query_tags_version": "2.3.0",
9+
"dbt_snowflake_query_tags_version": "2.3.1",
1010
"app": "dbt",
1111
"dbt_version": "1.4.0",
1212
"project_name": "my_project",
@@ -45,7 +45,7 @@ Query tags are used solely for attaching the `is_incremental` flag, as this isn'
4545

4646
```json
4747
{
48-
"dbt_snowflake_query_tags_version": "2.3.0",
48+
"dbt_snowflake_query_tags_version": "2.3.1",
4949
"app": "dbt",
5050
"is_incremental": true
5151
}
@@ -96,6 +96,59 @@ query-comment:
9696

9797
That's it! All dbt-issued queries will now be tagged.
9898

99+
## Adding additional metadata
100+
101+
### Query comments
102+
103+
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.
104+
105+
### Query tags
106+
107+
To extend the information added in the query tags, set the [query_tag](https://docs.getdbt.com/reference/resource-configs/snowflake-configs#query-tags) config value to a mapping type. Examples:
108+
109+
#### Compatible config
110+
111+
Model
112+
```sql
113+
{{ config(
114+
query_tag = {'team': 'data'}
115+
) }}
116+
117+
select ...
118+
```
119+
120+
Results in a final query tag of
121+
```
122+
'{"team": "data", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": true}'
123+
```
124+
125+
the additional information is added by this package.
126+
127+
#### Incompatible config
128+
129+
Using a non-mapping type in the `query_tag` config will result in a warning, and the config being ignored.
130+
131+
Model
132+
```sql
133+
{{ config(
134+
query_tag = 'data team'
135+
) }}
136+
137+
select ...
138+
```
139+
140+
Leads to a warning
141+
```
142+
dbt-snowflake-query-tags warning: the query_tag config value of 'data team' 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.
143+
```
144+
145+
Results in a final query tag of
146+
```
147+
'{"app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": false}'
148+
```
149+
150+
Note that the query_tag value of 'data team' is not present.
151+
99152
## Contributing
100153

101154
### Adding a CHANGELOG Entry

macros/query_comment.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{%- set comment_dict = {} -%}
33
{%- do comment_dict.update(
44
app='dbt',
5-
dbt_snowflake_query_tags_version='2.3.0',
5+
dbt_snowflake_query_tags_version='2.3.1',
66
dbt_version=dbt_version,
77
project_name=project_name,
88
target_name=target.name,

macros/query_tags.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
{%- do query_tag.update(
1616
app='dbt',
17-
dbt_snowflake_query_tags_version='2.3.0',
17+
dbt_snowflake_query_tags_version='2.3.1',
1818
) -%}
1919

2020
{% if thread_id %}

0 commit comments

Comments
 (0)