Skip to content

Commit

Permalink
Merge pull request #18 from get-select/handle_non_mappings_gracefully
Browse files Browse the repository at this point in the history
Handle non mappings gracefully
  • Loading branch information
NiallRees authored Aug 18, 2023
2 parents 630b422 + 1ff81b2 commit c5f7b7e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ An example query comment contains:

```json
{
"dbt_snowflake_query_tags_version": "2.3.0",
"dbt_snowflake_query_tags_version": "2.3.1",
"app": "dbt",
"dbt_version": "1.4.0",
"project_name": "my_project",
Expand Down Expand Up @@ -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.0",
"dbt_snowflake_query_tags_version": "2.3.1",
"app": "dbt",
"is_incremental": true
}
Expand Down Expand Up @@ -96,6 +96,59 @@ query-comment:

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

## Adding additional metadata

### 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.

### Query tags

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:

#### Compatible config

Model
```sql
{{ config(
query_tag = {'team': 'data'}
) }}
select ...
```

Results in a final query tag of
```
'{"team": "data", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": true}'
```
the additional information is added by this package.
#### Incompatible config
Using a non-mapping type in the `query_tag` config will result in a warning, and the config being ignored.
Model
```sql
{{ config(
query_tag = 'data team'
) }}
select ...
```

Leads to a warning
```
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.
```

Results in a final query tag of
```
'{"app": "dbt", "dbt_snowflake_query_tags_version": "2.3.1", "is_incremental": false}'
```

Note that the query_tag value of 'data team' is not present.

## Contributing

### Adding a CHANGELOG Entry
Expand Down
2 changes: 1 addition & 1 deletion macros/query_comment.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- set comment_dict = {} -%}
{%- do comment_dict.update(
app='dbt',
dbt_snowflake_query_tags_version='2.3.0',
dbt_snowflake_query_tags_version='2.3.1',
dbt_version=dbt_version,
project_name=project_name,
target_name=target.name,
Expand Down
2 changes: 1 addition & 1 deletion macros/query_tags.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

{%- do query_tag.update(
app='dbt',
dbt_snowflake_query_tags_version='2.3.0',
dbt_snowflake_query_tags_version='2.3.1',
) -%}

{% if thread_id %}
Expand Down

0 comments on commit c5f7b7e

Please sign in to comment.