Skip to content

Commit

Permalink
Merge pull request #31 from get-select/support_extra_query_tag_meta
Browse files Browse the repository at this point in the history
Support extra kwarg in query tag meta
  • Loading branch information
NiallRees authored May 15, 2024
2 parents 52f1167 + 0820a6f commit e69aad6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changes/2.5.0.md
Original file line number Diff line number Diff line change
@@ -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))


8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: 'dbt_snowflake_query_tags'
version: '2.4.1'
version: '2.5.0'
config-version: 2
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 = 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,
Expand Down
9 changes: 5 additions & 4 deletions macros/query_tags.sql
Original file line number Diff line number Diff line change
@@ -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 = {} %}
Expand Down Expand Up @@ -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 %}
Expand Down

0 comments on commit e69aad6

Please sign in to comment.