Skip to content

Commit

Permalink
Add query tag back to incremental models (#1212)
Browse files Browse the repository at this point in the history
* add query tag back to incremental models

* fix query tag test
  • Loading branch information
mikealfare authored Oct 17, 2024
1 parent 7dea145 commit 8825ccb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

{% materialization incremental, adapter='snowflake', supported_languages=['sql', 'python'] -%}

{% set original_query_tag = set_query_tag() %}

{#-- Set vars --#}
{%- set full_refresh_mode = (should_full_refresh()) -%}
Expand Down
34 changes: 13 additions & 21 deletions tests/functional/query_tag/test_query_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from dbt.tests.util import run_dbt


snapshots__snapshot_query_tag_sql = """
{% snapshot snapshot_query_tag %}
{{
Expand All @@ -14,16 +15,15 @@
}}
select 1 as id, 'blue' as color
{% endsnapshot %}
"""


models__table_model_query_tag_sql = """
{{ config(materialized = 'table') }}
select 1 as id
"""


models__models_config_yml = """
version: 2
Expand All @@ -33,23 +33,21 @@
- name: id
data_tests:
- unique
"""


models__view_model_query_tag_sql = """
{{ config(materialized = 'view') }}
select 1 as id
"""


models__incremental_model_query_tag_sql = """
{{ config(materialized = 'incremental', unique_key = 'id') }}
select 1 as id
"""


macros__check_tag_sql = """
{% macro check_query_tag() %}
Expand All @@ -61,12 +59,12 @@
{% endif %}
{% endmacro %}
"""


seeds__seed_query_tag_csv = """id
1
"""
""".strip()


class TestQueryTag:
Expand Down Expand Up @@ -95,20 +93,14 @@ def seeds(self):
def project_config_update(self, prefix):
return {
"config-version": 2,
"models": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"seeds": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"snapshots": {
"tests": {"query_tag": prefix, "post-hook": "{{ check_tag() }}"},
},
"models": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
"seeds": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
"snapshots": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"},
"tests": {"test": {"query_tag": prefix, "post-hook": "{{ check_query_tag() }}"}},
}

def build_all_with_query_tags(self, project, prefix):
run_dbt(["build", "--vars", '{{"check_tag": "{}"}}'.format(prefix)])
run_dbt(["build", "--vars", '{{"query_tag": "{}"}}'.format(prefix)])

def test_snowflake_query_tag(self, project, prefix):
self.build_all_with_query_tags(project, prefix)
Expand All @@ -130,7 +122,7 @@ def profiles_config_update(self, prefix):
return {"query_tag": prefix}

def build_all_with_query_tags(self, project, prefix):
run_dbt(["build", "--vars", '{{"check_tag": "{}"}}'.format(prefix)])
run_dbt(["build", "--vars", '{{"query_tag": "{}"}}'.format(prefix)])

def test_snowflake_query_tag(self, project, prefix):
self.build_all_with_query_tags(project, prefix)
Expand Down

0 comments on commit 8825ccb

Please sign in to comment.