Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support query tags in tests #210

Merged
merged 11 commits into from
Aug 22, 2022
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20220815-233505.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Support query tags in dbt tests using the `+query_tag` config in `dbt_project.yml`
time: 2022-08-15T23:35:05.967484-06:00
custom:
Author: matt-winkler
Issue: "211"
PR: "210"
8 changes: 8 additions & 0 deletions dbt/include/snowflake/macros/materializations/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{%- materialization test, adapter='snowflake' -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd hope that all of this could just be:

{%- materialization test, adapter='snowflake' -%}
    {% set original_query_tag = set_query_tag() %}
    {% set relations = materialization_test_default() %}
    {% do unset_query_tag(original_query_tag) %}
    {{ return(relations) }}
{% endmaterialization %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right on! had that initially, then went to the full copy from dbt-core. Will shift back, test etc. Thanks @jtcohen6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jtcohen6 with this set up, I can configure query tags to run on tests from the dbt_project.yml:

tests:
  dev_project_snowflake:
    example:
      +query_tag: mw_dev_test

BUT, I can't set them from a schema.yml:

  - name: my_second_dbt_model
    description: "A starter dbt model"
    columns:
      - name: id
        description: "The primary key for this table"
        tests:
          - unique:
              config:
                query_tag: mw_dev_test #nothing happens on snowflake with this setup
          - not_null

Should I be able to make this setting in both places?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-winkler Good catch. Unfortunately, this will have to come as a separate unit of work: dbt-labs/dbt-core#5532


{% set original_query_tag = set_query_tag() %}
{% set relations = materialization_test_default() %}
{% do unset_query_tag(original_query_tag) %}
{{ return(relations) }}

{%- endmaterialization -%}
8 changes: 8 additions & 0 deletions tests/integration/query_tag_tests/models/models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2

models:
- name: view_model_query_tag
columns:
- name: id
tests:
- unique
6 changes: 6 additions & 0 deletions tests/integration/query_tag_tests/test_query_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def project_config(self):
'post-hook': '{{ check_query_tag() }}'
},
},
'tests': {
'test': {
'query_tag': self.prefix,
'post-hook': '{{ check_query_tag() }}'
}
},
}

def build_all_with_query_tags(self):
Expand Down