├── .changes ├── unreleased │ └── .gitkeep ├── 1.0.0.md ├── 1.1.3.md ├── 1.1.1.md ├── 2.0.2.md ├── 1.1.0.md ├── 2.3.0.md ├── 2.0.1.md ├── 2.3.1.md ├── 2.3.3.md ├── 2.4.1.md ├── 2.5.0.md ├── 2.2.0.md ├── 2.0.0.md ├── 2.1.0.md ├── 2.5.4.md ├── 2.5.2.md ├── 2.5.3.md ├── 1.1.2.md ├── 2.5.1.md ├── header.tpl.md ├── 2.3.2.md └── 2.4.0.md ├── supported_adapters.env ├── integration_tests ├── packages.yml ├── tests │ ├── dbt_project_configured_meta │ │ └── test_2.sql │ └── test.sql ├── models │ ├── materialized_view.sql │ ├── materialized_ephemeral.sql │ ├── materialized_incremental.sql │ └── materialized_table.sql ├── package-lock.yml ├── seeds │ └── test_seed.csv ├── snapshots │ └── snapshot.sql ├── dbt_project.yml └── profiles.yml ├── .gitignore ├── dbt_project.yml ├── .editorconfig ├── tox.ini ├── .github └── workflows │ ├── ci_dbt_test_package.yml │ ├── main_test_package.yml │ └── ci_test_package.yml ├── LICENSE ├── .changie.yaml ├── macros ├── query_tags.sql └── query_comment.sql ├── CHANGELOG.md └── README.md /.changes/unreleased/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /supported_adapters.env: -------------------------------------------------------------------------------- 1 | SUPPORTED_ADAPTERS=snowflake 2 | -------------------------------------------------------------------------------- /integration_tests/packages.yml: -------------------------------------------------------------------------------- 1 | packages: 2 | - local: ../ 3 | -------------------------------------------------------------------------------- /integration_tests/tests/dbt_project_configured_meta/test_2.sql: -------------------------------------------------------------------------------- 1 | select 1 2 | where false 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | dbt_packages/ 3 | logs/ 4 | logfile 5 | .DS_Store 6 | dbt_internal_packages/ -------------------------------------------------------------------------------- /dbt_project.yml: -------------------------------------------------------------------------------- 1 | name: 'dbt_snowflake_query_tags' 2 | version: '2.5.4' 3 | config-version: 2 4 | -------------------------------------------------------------------------------- /integration_tests/models/materialized_view.sql: -------------------------------------------------------------------------------- 1 | {{ config(materialized='view') }} 2 | 3 | select 1 as a 4 | -------------------------------------------------------------------------------- /integration_tests/models/materialized_ephemeral.sql: -------------------------------------------------------------------------------- 1 | {{ config(materialized='ephemeral') }} 2 | 3 | select 1 as a 4 | -------------------------------------------------------------------------------- /integration_tests/package-lock.yml: -------------------------------------------------------------------------------- 1 | packages: 2 | - local: ../ 3 | sha1_hash: de2deba3d66ce03d8c02949013650cc9b94f6030 4 | -------------------------------------------------------------------------------- /integration_tests/tests/test.sql: -------------------------------------------------------------------------------- 1 | {{ config(meta = { 2 | 'team': '1' 3 | }) }} 4 | 5 | select 1 6 | where false 7 | -------------------------------------------------------------------------------- /.changes/1.0.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 1.0.0 - February 08, 2023 2 | 3 | ### Features 4 | 5 | - Initial release 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/1.1.3.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 1.1.3 - February 13, 2023 2 | 3 | ### Fixes 4 | 5 | - Dedupe refs ([#6](https://github.com/get-select/dbt-snowflake-query-tags/pull/6)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/1.1.1.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 1.1.1 - February 12, 2023 2 | 3 | ### Fixes 4 | 5 | - Fix refs list ([#4](https://github.com/get-select/dbt-snowflake-query-tags/pull/4)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.0.2.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.0.2 - May 12, 2023 2 | 3 | ### Features 4 | 5 | - Support dbt 1.5.0 ([#11](https://github.com/get-select/dbt-snowflake-query-tags/pull/11)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/1.1.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 1.1.0 - February 11, 2023 2 | 3 | ### Features 4 | 5 | - Add node refs to tag ([#1](https://github.com/get-select/dbt-snowflake-query-tags/pull/1)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.3.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.3.0 - June 29, 2023 2 | 3 | ### Features 4 | 5 | - Add thread_id to query tag ([#16](https://github.com/get-select/dbt-snowflake-query-tags/pull/16)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.0.1.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.0.1 - February 24, 2023 2 | 3 | ### Features 4 | 5 | - Add dbt tags to comment metadata ([#9](https://github.com/get-select/dbt-snowflake-query-tags/pull/9)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.3.1.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.3.1 - August 18, 2023 2 | 3 | ### Features 4 | 5 | - Handle non-mapping configs gracefully ([#17](https://github.com/get-select/dbt-snowflake-query-tags/pull/17)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.3.3.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.3.3 - January 29, 2024 2 | 3 | ### Features 4 | 5 | - Remove warning on session level query tag ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.4.1.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.4.1 - May 14, 2024 2 | 3 | ### Fixes 4 | 5 | - Check for local_md5 as only added in dbt 1.4.0 ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.5.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.5.0 - May 15, 2024 2 | 3 | ### Features 4 | 5 | - Support custom extra kwarg for query tag meta ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.2.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.2.0 - June 23, 2023 2 | 3 | ### Features 4 | 5 | - Add full_refresh, which and invocation_command to comment ([#15](https://github.com/get-select/dbt-snowflake-query-tags/pull/15)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /.changes/2.0.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.0.0 - February 24, 2023 2 | 3 | ### Fixes 4 | 5 | - Use query comments and query tags to avoid query tag character limit ([#8](https://github.com/get-select/dbt-snowflake-query-tags/pull/8)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /integration_tests/models/materialized_incremental.sql: -------------------------------------------------------------------------------- 1 | {{ config(materialized='incremental', tags=['a', 'b', 'c'], query_tag="{'test': 'test'}") }} 2 | 3 | select 1 as a 4 | 5 | -- {{ ref('materialized_table') }} 6 | -- {{ ref('materialized_view') }} 7 | -------------------------------------------------------------------------------- /integration_tests/seeds/test_seed.csv: -------------------------------------------------------------------------------- 1 | MONTH,SERVICE,SPEND 2 | 2022-04-01,Storage,1.136266305 3 | 2022-04-01,Compute,912.772222176 4 | 2022-04-01,Adj For Incl Cloud Services,-74.921528302 5 | 2022-04-01,Cloud Services,74.921528302 6 | 2022-04-01,Automatic Clustering,0.051113362 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.yml] 12 | indent_size = 2 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.changes/2.1.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.1.0 - May 26, 2023 2 | 3 | ### Features 4 | 5 | - Add dbt meta to comment metadata ([#13](https://github.com/get-select/dbt-snowflake-query-tags/pull/13)) 6 | 7 | ### Contributors 8 | - [@pratik60](https://github.com/pratik60) (Features) 9 | 10 | -------------------------------------------------------------------------------- /.changes/2.5.4.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.5.4 - November 13, 2025 2 | 3 | ### Fixes 4 | 5 | - For Fusion, allow quoting dict in string ([#46](https://github.com/get-select/dbt-snowflake-query-tags/pull/46)) 6 | 7 | ### Contributors 8 | - [@b-per](https://github.com/b-per) (Fixes) 9 | 10 | -------------------------------------------------------------------------------- /.changes/2.5.2.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.5.2 - July 08, 2025 2 | 3 | ### Fixes 4 | 5 | - removed depricated config ([#39](https://github.com/get-select/dbt-snowflake-query-tags/pull/39)) 6 | 7 | ### Contributors 8 | - [@colin-rogers-dbt](https://github.com/colin-rogers-dbt) (Fixes) 9 | 10 | -------------------------------------------------------------------------------- /.changes/2.5.3.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.5.3 - July 09, 2025 2 | 3 | ### Fixes 4 | 5 | - fixed failing integration tests ([#42](https://github.com/get-select/dbt-snowflake-query-tags/pull/42)) 6 | 7 | ### Contributors 8 | - [@colin-rogers-dbt](https://github.com/colin-rogers-dbt) (Fixes) 9 | 10 | -------------------------------------------------------------------------------- /integration_tests/snapshots/snapshot.sql: -------------------------------------------------------------------------------- 1 | {% snapshot test_snapshot %} 2 | 3 | {{ 4 | config( 5 | target_schema=target.schema, 6 | strategy='check', 7 | unique_key='a', 8 | check_cols=['b'], 9 | ) 10 | }} 11 | 12 | select 1 as a, 2 as b 13 | 14 | {% endsnapshot %} 15 | -------------------------------------------------------------------------------- /.changes/1.1.2.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 1.1.2 - February 13, 2023 2 | 3 | ### Features 4 | 5 | - Support dispatch order for macro configuration ([#2](https://github.com/get-select/dbt-snowflake-query-tags/pull/2)) 6 | 7 | ### Contributors 8 | - [@robscriva](https://github.com/robscriva) (Features) 9 | 10 | -------------------------------------------------------------------------------- /.changes/2.5.1.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.5.1 - June 18, 2025 2 | 3 | ### Fixes 4 | 5 | - Fixed incompatability with dbt version 1.10 ([#36](https://github.com/get-select/dbt-snowflake-query-tags/pull/36)) 6 | 7 | ### Contributors 8 | - [@jeff-skoldberg-gmds](https://github.com/jeff-skoldberg-gmds) (Fixes) 9 | 10 | -------------------------------------------------------------------------------- /integration_tests/models/materialized_table.sql: -------------------------------------------------------------------------------- 1 | {{ 2 | config( 3 | meta={ 4 | "owner": "@alice", 5 | "model_maturity": "in dev" 6 | }, 7 | materialized="table", 8 | tags='a', 9 | query_tag="this will generate a warning" 10 | ) 11 | }} 12 | 13 | select 1 as a 14 | -------------------------------------------------------------------------------- /.changes/header.tpl.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), 6 | and is generated by [Changie](https://github.com/miniscruff/changie). 7 | -------------------------------------------------------------------------------- /.changes/2.3.2.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.3.2 - January 18, 2024 2 | 3 | ### Features 4 | 5 | - Support for query tags from profiles.yml and environment variables ([#21](https://github.com/get-select/dbt-snowflake-query-tags/pull/21)) 6 | - Add support for custom query comment keys and values ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) 7 | 8 | ### Contributors 9 | - [@maddoc1](https://github.com/maddoc1) (Features) 10 | 11 | -------------------------------------------------------------------------------- /.changes/2.4.0.md: -------------------------------------------------------------------------------- 1 | ## dbt-snowflake-query-tags 2.4.0 - May 14, 2024 2 | 3 | ### Features 4 | 5 | - Add raw_code_hash to query comment ([#26](https://github.com/get-select/dbt-snowflake-query-tags/pull/26)) 6 | - Add run_started_at to query comment ([#27](https://github.com/get-select/dbt-snowflake-query-tags/pull/27)) 7 | 8 | ### Contributors 9 | - [@bmoore813](https://github.com/bmoore813) (Features) 10 | - [@bisset-a](https://github.com/bisset-a) (Features) 11 | -------------------------------------------------------------------------------- /integration_tests/dbt_project.yml: -------------------------------------------------------------------------------- 1 | name: 'dbt_snowflake_query_tags_tests' 2 | version: '1.0.0' 3 | config-version: 2 4 | 5 | profile: integration_tests 6 | 7 | flags: 8 | send_anonymous_usage_stats: false 9 | use_colors: true 10 | 11 | dispatch: 12 | - macro_namespace: dbt 13 | search_order: 14 | - dbt_snowflake_query_tags_tests 15 | - dbt_snowflake_query_tags 16 | - dbt 17 | 18 | query-comment: 19 | comment: '{{ dbt_snowflake_query_tags.get_query_comment(node, extra={"run_started_at": builtins.run_started_at | string }) }}' 20 | append: true # Snowflake removes prefixed comments. 21 | -------------------------------------------------------------------------------- /integration_tests/profiles.yml: -------------------------------------------------------------------------------- 1 | # HEY! This file is used in the dbt-snowflake-query-tags integrations tests with GitHub Actions. 2 | # You should __NEVER__ check credentials into version control. Thanks for reading :) 3 | 4 | integration_tests: 5 | target: snowflake 6 | outputs: 7 | snowflake: 8 | type: "snowflake" 9 | account: "{{ env_var('SNOWFLAKE_ACCOUNT') }}" 10 | user: "{{ env_var('SNOWFLAKE_USER') }}" 11 | password: "{{ env_var('DBT_ENV_SECRET_SNOWFLAKE_PASS') }}" 12 | role: "{{ env_var('SNOWFLAKE_ROLE') }}" 13 | database: "{{ env_var('SNOWFLAKE_DATABASE') }}" 14 | warehouse: "{{ env_var('SNOWFLAKE_WAREHOUSE') }}" 15 | schema: "{{ env_var('SNOWFLAKE_SCHEMA') }}" 16 | threads: 10 17 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | skipsdist = True 3 | envlist = snowflake 4 | 5 | [testenv] 6 | passenv = 7 | DBT_PROFILES_DIR 8 | GITHUB_SHA 9 | GITHUB_SHA_OVERRIDE 10 | SNOWFLAKE_ACCOUNT 11 | SNOWFLAKE_USER 12 | DBT_ENV_SECRET_SNOWFLAKE_PASS 13 | SNOWFLAKE_ROLE 14 | SNOWFLAKE_DATABASE 15 | SNOWFLAKE_WAREHOUSE 16 | SNOWFLAKE_SCHEMA 17 | 18 | [testenv:snowflake] 19 | changedir = integration_tests 20 | deps = dbt-snowflake~=1.5.0 21 | commands = 22 | dbt deps 23 | dbt build --full-refresh 24 | dbt build 25 | 26 | # Snowflake integration tests for centralized dbt testing 27 | # run dbt commands directly, assumes dbt is already installed in environment 28 | [testenv:dbt_integration_snowflake] 29 | changedir = integration_tests 30 | allowlist_externals = 31 | dbt 32 | skip_install = true 33 | commands = 34 | dbt deps 35 | dbt build --full-refresh --no-version-check 36 | dbt build --no-version-check -------------------------------------------------------------------------------- /.github/workflows/ci_dbt_test_package.yml: -------------------------------------------------------------------------------- 1 | # **what?** 2 | # Run tests for dbt-snowflake-query-tags against supported adapters 3 | 4 | # **why?** 5 | # To ensure that dbt-snowflake-query-tags works as expected with all supported adapters 6 | 7 | # **when?** 8 | # On every PR, and every push to main and when manually triggered 9 | 10 | name: Package Integration Tests 11 | 12 | on: 13 | push: 14 | branches: 15 | - main 16 | pull_request: 17 | workflow_dispatch: 18 | 19 | jobs: 20 | run-tests: 21 | uses: dbt-labs/dbt-package-testing/.github/workflows/run_tox.yml@v1 22 | with: 23 | SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_TEST_USER }} 24 | SNOWFLAKE_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }} 25 | SNOWFLAKE_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }} 26 | SNOWFLAKE_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }} 27 | SNOWFLAKE_SCHEMA: "integration_tests_snowflake_${{ github.run_number }}" 28 | secrets: 29 | SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }} 30 | DBT_ENV_SECRET_SNOWFLAKE_PASS: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 get-select 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/main_test_package.yml: -------------------------------------------------------------------------------- 1 | name: Main branch test package 2 | 3 | # triggers for the workflow 4 | on: 5 | workflow_dispatch: 6 | push: 7 | branches: 8 | - main 9 | 10 | env: 11 | # These are configured in GitHub secrets 12 | DBT_PROFILES_DIR: /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/integration_tests 13 | GITHUB_SHA_OVERRIDE: ${{ github.event.pull_request.head.sha }} # We need the commit hash of the pull request branch's head, the GITHUB_SHA env var is always the base branch in a pull_request_target trigger 14 | DBT_ENV_SECRET_SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }} 15 | DBT_ENV_SECRET_SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }} 16 | DBT_ENV_SECRET_SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }} 17 | DBT_ENV_SECRET_SNOWFLAKE_TEST_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }} 18 | DBT_ENV_SECRET_SNOWFLAKE_TEST_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }} 19 | DBT_ENV_SECRET_SNOWFLAKE_TEST_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }} 20 | 21 | jobs: 22 | integration-snowflake: 23 | runs-on: ubuntu-latest 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v2 28 | 29 | - name: Install tox 30 | run: python3 -m pip install tox 31 | 32 | - name: Run Snowflake Tests 33 | run: tox -e snowflake 34 | -------------------------------------------------------------------------------- /.github/workflows/ci_test_package.yml: -------------------------------------------------------------------------------- 1 | name: CI test package 2 | 3 | on: 4 | workflow_dispatch: 5 | # all PRs, important to note that `pull_request_target` workflows 6 | # will run in the context of the target branch of a PR 7 | pull_request_target: 8 | 9 | env: 10 | # These are configured in GitHub secrets 11 | DBT_PROFILES_DIR: /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/integration_tests 12 | GITHUB_SHA_OVERRIDE: ${{ github.event.pull_request.head.sha }} # We need the commit hash of the pull request branch's head, the GITHUB_SHA env var is always the base branch in a pull_request_target trigger 13 | SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }} 14 | SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_TEST_USER }} 15 | DBT_ENV_SECRET_SNOWFLAKE_PASS: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }} 16 | SNOWFLAKE_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }} 17 | SNOWFLAKE_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }} 18 | SNOWFLAKE_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }} 19 | SNOWFLAKE_SCHEMA: "integration_tests_snowflake_${{ github.run_number }}" 20 | 21 | 22 | jobs: 23 | integration-snowflake: 24 | runs-on: ubuntu-latest 25 | environment: 26 | name: Approve Integration Tests 27 | 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v2 31 | with: 32 | ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR 33 | 34 | - name: Install tox 35 | run: python3 -m pip install tox 36 | 37 | - name: Run Snowflake Tests 38 | run: tox -e snowflake 39 | -------------------------------------------------------------------------------- /.changie.yaml: -------------------------------------------------------------------------------- 1 | # Mainly from https://github.com/dbt-labs/dbt-core/blob/main/.changie.yaml 2 | 3 | changesDir: .changes 4 | unreleasedDir: unreleased 5 | headerPath: header.tpl.md 6 | changelogPath: CHANGELOG.md 7 | versionExt: md 8 | versionFormat: '## dbt-snowflake-query-tags {{.Version}} - {{.Time.Format "January 02, 2006"}}' 9 | kindFormat: '### {{.Kind}}' 10 | changeFormat: '- {{.Body}} ([#{{.Custom.PR}}](https://github.com/get-select/dbt-snowflake-query-tags/pull/{{.Custom.PR}}))' 11 | kinds: 12 | - label: Breaking Changes 13 | - label: Features 14 | - label: Fixes 15 | - label: Docs 16 | newlines: 17 | afterChangelogHeader: 1 18 | afterKind: 1 19 | afterChangelogVersion: 1 20 | beforeKind: 1 21 | endOfVersion: 1 22 | custom: 23 | - key: Author 24 | label: GitHub Username(s) (separated by a single space if multiple) 25 | type: string 26 | minLength: 3 27 | - key: PR 28 | label: GitHub Pull Request Number 29 | type: int 30 | minInt: 1 31 | 32 | footerFormat: | 33 | {{- $contributorDict := dict }} 34 | {{- /* any names added to this list should be all lowercase for later matching purposes */}} 35 | {{- $core_team := list "niallrees" "ian-whitestone" }} 36 | {{- range $change := .Changes }} 37 | {{- $authorList := splitList " " $change.Custom.Author }} 38 | {{- /* loop through all authors for a PR */}} 39 | {{- range $author := $authorList }} 40 | {{- $authorLower := lower $author }} 41 | {{- /* we only want to include non-core team contributors */}} 42 | {{- if not (has $authorLower $core_team)}} 43 | {{- /* Docs kind link back to dbt-docs instead of dbt-core PRs */}} 44 | {{- $prLink := $change.Kind }} 45 | {{- /* check if this contributor has other PRs associated with them already */}} 46 | {{- if hasKey $contributorDict $author }} 47 | {{- $prList := get $contributorDict $author }} 48 | {{- $prList = append $prList $prLink }} 49 | {{- $contributorDict := set $contributorDict $author $prList }} 50 | {{- else }} 51 | {{- $prList := list $prLink }} 52 | {{- $contributorDict := set $contributorDict $author $prList }} 53 | {{- end }} 54 | {{- end}} 55 | {{- end}} 56 | {{- end }} 57 | {{- /* no indentation here for formatting so the final markdown doesn't have unneeded indentations */}} 58 | {{- if $contributorDict}} 59 | ### Contributors 60 | {{- range $k,$v := $contributorDict }} 61 | - [@{{$k}}](https://github.com/{{$k}}) ({{ range $index, $element := $v }}{{if $index}}, {{end}}{{$element}}{{end}}) 62 | {{- end }} 63 | {{- end }} 64 | -------------------------------------------------------------------------------- /macros/query_tags.sql: -------------------------------------------------------------------------------- 1 | {% macro set_query_tag(extra = {}) -%} 2 | {{ return(adapter.dispatch('set_query_tag', 'dbt_snowflake_query_tags')(extra=extra)) }} 3 | {%- endmacro %} 4 | 5 | {% macro default__set_query_tag(extra = {}) -%} 6 | {# Get session level query tag #} 7 | {% set original_query_tag = get_current_query_tag() %} 8 | {% set original_query_tag_parsed = {} %} 9 | 10 | {% if original_query_tag %} 11 | {% if fromjson(original_query_tag) is mapping %} 12 | {% set original_query_tag_parsed = fromjson(original_query_tag) %} 13 | {% endif %} 14 | {% endif %} 15 | 16 | {# The env_vars_to_query_tag_list should contain an environment variables list to construct query tag dict #} 17 | {% set env_var_query_tags = {} %} 18 | {% if var('env_vars_to_query_tag_list', '') %} {# Get a list of env vars from env_vars_to_query_tag_list variable to add additional query tags #} 19 | {% for k in var('env_vars_to_query_tag_list') %} 20 | {% set v = env_var(k, '') %} 21 | {% do env_var_query_tags.update({k.lower(): v}) if v %} 22 | {% endfor %} 23 | {% endif %} 24 | 25 | {# Start with any model-configured dict #} 26 | {% set query_tag = config.get('query_tag', default={}) %} 27 | 28 | {# Handle the case where the query tag is a dict but quoted. This is required for Fusion. #} 29 | {% if query_tag is string and fromjson(query_tag[1:-1]) is mapping %} 30 | {% set query_tag = fromjson(query_tag[1:-1]) %} 31 | {% endif %} 32 | 33 | {% if query_tag is not mapping %} 34 | {% do log("dbt-snowflake-query-tags warning: the query_tag config value of '{}' 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.".format(query_tag), True) %} 35 | {% set query_tag = {} %} {# If the user has set the query tag config as a non mapping type, start fresh #} 36 | {% endif %} 37 | 38 | {% do query_tag.update(original_query_tag_parsed) %} 39 | {% do query_tag.update(env_var_query_tags) %} 40 | {% do query_tag.update(extra) %} 41 | 42 | {%- do query_tag.update( 43 | app='dbt', 44 | dbt_snowflake_query_tags_version='2.5.0', 45 | ) -%} 46 | 47 | {% if thread_id %} 48 | {%- do query_tag.update( 49 | thread_id=thread_id 50 | ) -%} 51 | {% endif %} 52 | 53 | 54 | {# We have to bring is_incremental through here because its not available in the comment context #} 55 | {% if model.resource_type == 'model' %} 56 | {%- do query_tag.update( 57 | is_incremental=is_incremental() 58 | ) -%} 59 | {% endif %} 60 | 61 | {% set query_tag_json = tojson(query_tag) %} 62 | {{ log("Setting query_tag to '" ~ query_tag_json ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }} 63 | {% do run_query("alter session set query_tag = '{}'".format(query_tag_json)) %} 64 | {{ return(original_query_tag)}} 65 | {% endmacro %} 66 | 67 | {% macro unset_query_tag(original_query_tag) -%} 68 | {{ return(adapter.dispatch('unset_query_tag', 'dbt_snowflake_query_tags')(original_query_tag)) }} 69 | {%- endmacro %} 70 | 71 | {% macro default__unset_query_tag(original_query_tag) -%} 72 | {% if original_query_tag %} 73 | {{ log("Resetting query_tag to '" ~ original_query_tag ~ "'.") }} 74 | {% do run_query("alter session set query_tag = '{}'".format(original_query_tag)) %} 75 | {% else %} 76 | {{ log("No original query_tag, unsetting parameter.") }} 77 | {% do run_query("alter session unset query_tag") %} 78 | {% endif %} 79 | {% endmacro %} 80 | -------------------------------------------------------------------------------- /macros/query_comment.sql: -------------------------------------------------------------------------------- 1 | {% macro get_query_comment(node, extra = {}) %} 2 | {%- set comment_dict = extra -%} 3 | {%- do comment_dict.update( 4 | app='dbt', 5 | dbt_snowflake_query_tags_version='2.5.0', 6 | dbt_version=dbt_version, 7 | project_name=project_name, 8 | target_name=target.name, 9 | target_database=target.database, 10 | target_schema=target.schema, 11 | invocation_id=invocation_id, 12 | run_started_at=run_started_at.astimezone(modules.pytz.utc).isoformat(), 13 | full_refresh=flags.FULL_REFRESH, 14 | which=flags.WHICH, 15 | ) -%} 16 | 17 | {%- if node is not none -%} 18 | {%- do comment_dict.update( 19 | node_name=node.name, 20 | node_alias=node.alias, 21 | node_package_name=node.package_name, 22 | node_original_file_path=node.original_file_path, 23 | node_database=node.database, 24 | node_schema=node.schema, 25 | node_id=node.unique_id, 26 | node_resource_type=node.resource_type, 27 | node_meta=node.config.meta, 28 | node_tags=node.tags, 29 | ) -%} 30 | 31 | {%- if flags.INVOCATION_COMMAND -%} 32 | {%- do comment_dict.update( 33 | invocation_command=flags.INVOCATION_COMMAND 34 | ) -%} 35 | {%- endif -%} 36 | 37 | {%- if node.resource_type != ('seed') -%} {# Otherwise this throws an error saying 'Seeds cannot depend on other nodes.' #} 38 | {%- if node.refs is defined -%} 39 | {% set refs = [] %} 40 | {% for ref in node.refs %} 41 | {%- if (dbt_version.split('.')[0] | int > 1) 42 | or (dbt_version.split('.')[0] | int == 1 and dbt_version.split('.')[1] | int >= 5) -%} 43 | {%- do refs.append(ref.name) -%} 44 | {%- else -%} 45 | {%- do refs.append(ref[0]) -%} 46 | {%- endif -%} 47 | {% endfor %} 48 | {%- do comment_dict.update( 49 | node_refs=refs | unique | list 50 | ) -%} 51 | {%- endif -%} 52 | {%- endif -%} 53 | {%- if node.resource_type == 'model' -%} 54 | {%- do comment_dict.update( 55 | materialized=node.config.materialized, 56 | ) -%} 57 | {%- endif -%} 58 | 59 | {%- if node.raw_code is not none and local_md5 -%} 60 | {%- do comment_dict.update({ 61 | "raw_code_hash": local_md5(node.raw_code) 62 | }) -%} 63 | {%- endif -%} 64 | {%- endif -%} 65 | 66 | {%- if env_var('DBT_CLOUD_PROJECT_ID', False) -%} 67 | {%- do comment_dict.update( 68 | dbt_cloud_project_id=env_var('DBT_CLOUD_PROJECT_ID') 69 | ) -%} 70 | {%- endif -%} 71 | 72 | {%- if env_var('DBT_CLOUD_JOB_ID', False) -%} 73 | {%- do comment_dict.update( 74 | dbt_cloud_job_id=env_var('DBT_CLOUD_JOB_ID') 75 | ) -%} 76 | {%- endif -%} 77 | 78 | {%- if env_var('DBT_CLOUD_RUN_ID', False) -%} 79 | {%- do comment_dict.update( 80 | dbt_cloud_run_id=env_var('DBT_CLOUD_RUN_ID') 81 | ) -%} 82 | {%- endif -%} 83 | 84 | {%- if env_var('DBT_CLOUD_RUN_REASON_CATEGORY', False) -%} 85 | {%- do comment_dict.update( 86 | dbt_cloud_run_reason_category=env_var('DBT_CLOUD_RUN_REASON_CATEGORY') 87 | ) -%} 88 | {%- endif -%} 89 | 90 | {%- if env_var('DBT_CLOUD_RUN_REASON', False) -%} 91 | {%- do comment_dict.update( 92 | dbt_cloud_run_reason=env_var('DBT_CLOUD_RUN_REASON') 93 | ) -%} 94 | {%- endif -%} 95 | 96 | {{ return(tojson(comment_dict)) }} 97 | {% endmacro %} 98 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), 6 | and is generated by [Changie](https://github.com/miniscruff/changie). 7 | 8 | ## dbt-snowflake-query-tags 2.5.4 - November 13, 2025 9 | 10 | ### Fixes 11 | 12 | - For Fusion, allow quoting dict in string ([#46](https://github.com/get-select/dbt-snowflake-query-tags/pull/46)) 13 | 14 | ### Contributors 15 | - [@b-per](https://github.com/b-per) (Fixes) 16 | 17 | 18 | ## dbt-snowflake-query-tags 2.5.3 - July 09, 2025 19 | 20 | ### Fixes 21 | 22 | - fixed failing integration tests ([#42](https://github.com/get-select/dbt-snowflake-query-tags/pull/42)) 23 | 24 | ### Contributors 25 | - [@colin-rogers-dbt](https://github.com/colin-rogers-dbt) (Fixes) 26 | 27 | 28 | ## dbt-snowflake-query-tags 2.5.2 - July 08, 2025 29 | 30 | ### Fixes 31 | 32 | - removed depricated config ([#39](https://github.com/get-select/dbt-snowflake-query-tags/pull/39)) 33 | 34 | ### Contributors 35 | - [@colin-rogers-dbt](https://github.com/colin-rogers-dbt) (Fixes) 36 | 37 | 38 | ## dbt-snowflake-query-tags 2.5.1 - June 18, 2025 39 | 40 | ### Fixes 41 | 42 | - Fixed incompatability with dbt version 1.10 ([#36](https://github.com/get-select/dbt-snowflake-query-tags/pull/36)) 43 | 44 | ### Contributors 45 | - [@jeff-skoldberg-gmds](https://github.com/jeff-skoldberg-gmds) (Fixes) 46 | 47 | 48 | ## dbt-snowflake-query-tags 2.5.0 - May 15, 2024 49 | 50 | ### Features 51 | 52 | - Support custom extra kwarg for query tag meta ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) 53 | 54 | 55 | 56 | ## dbt-snowflake-query-tags 2.4.1 - May 14, 2024 57 | 58 | ### Fixes 59 | 60 | - Check for local_md5 as only added in dbt 1.4.0 ([#30](https://github.com/get-select/dbt-snowflake-query-tags/pull/30)) 61 | 62 | 63 | 64 | ## dbt-snowflake-query-tags 2.4.0 - May 14, 2024 65 | 66 | ### Features 67 | 68 | - Add raw_code_hash to query comment ([#26](https://github.com/get-select/dbt-snowflake-query-tags/pull/26)) 69 | - Add run_started_at to query comment ([#27](https://github.com/get-select/dbt-snowflake-query-tags/pull/27)) 70 | 71 | ### Contributors 72 | - [@bmoore813](https://github.com/bmoore813) (Features) 73 | - [@bisset-a](https://github.com/bisset-a) (Features) 74 | 75 | ## dbt-snowflake-query-tags 2.3.3 - January 29, 2024 76 | 77 | ### Features 78 | 79 | - Remove warning on session level query tag ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) 80 | 81 | 82 | 83 | ## dbt-snowflake-query-tags 2.3.2 - January 18, 2024 84 | 85 | ### Features 86 | 87 | - Support for query tags from profiles.yml and environment variables ([#21](https://github.com/get-select/dbt-snowflake-query-tags/pull/21)) 88 | - Add support for custom query comment keys and values ([#22](https://github.com/get-select/dbt-snowflake-query-tags/pull/22)) 89 | 90 | ### Contributors 91 | - [@maddoc1](https://github.com/maddoc1) (Features) 92 | 93 | 94 | ## dbt-snowflake-query-tags 2.3.1 - August 18, 2023 95 | 96 | ### Features 97 | 98 | - Handle non-mapping configs gracefully ([#17](https://github.com/get-select/dbt-snowflake-query-tags/pull/17)) 99 | 100 | 101 | 102 | ## dbt-snowflake-query-tags 2.3.0 - June 29, 2023 103 | 104 | ### Features 105 | 106 | - Add thread_id to query tag ([#16](https://github.com/get-select/dbt-snowflake-query-tags/pull/16)) 107 | 108 | 109 | 110 | ## dbt-snowflake-query-tags 2.2.0 - June 23, 2023 111 | 112 | ### Features 113 | 114 | - Add full_refresh, which and invocation_command to comment ([#15](https://github.com/get-select/dbt-snowflake-query-tags/pull/15)) 115 | 116 | 117 | 118 | ## dbt-snowflake-query-tags 2.1.0 - May 26, 2023 119 | 120 | ### Features 121 | 122 | - Add dbt meta to comment metadata ([#13](https://github.com/get-select/dbt-snowflake-query-tags/pull/13)) 123 | 124 | ### Contributors 125 | - [@pratik60](https://github.com/pratik60) (Features) 126 | 127 | 128 | ## dbt-snowflake-query-tags 2.0.2 - May 12, 2023 129 | 130 | ### Features 131 | 132 | - Support dbt 1.5.0 ([#11](https://github.com/get-select/dbt-snowflake-query-tags/pull/11)) 133 | 134 | 135 | 136 | ## dbt-snowflake-query-tags 2.0.1 - February 24, 2023 137 | 138 | ### Features 139 | 140 | - Add dbt tags to comment metadata ([#9](https://github.com/get-select/dbt-snowflake-query-tags/pull/9)) 141 | 142 | 143 | 144 | ## dbt-snowflake-query-tags 2.0.0 - February 24, 2023 145 | 146 | ### Fixes 147 | 148 | - Use query comments and query tags to avoid query tag character limit ([#8](https://github.com/get-select/dbt-snowflake-query-tags/pull/8)) 149 | 150 | 151 | 152 | ## dbt-snowflake-query-tags 1.1.3 - February 13, 2023 153 | 154 | ### Fixes 155 | 156 | - Dedupe refs ([#6](https://github.com/get-select/dbt-snowflake-query-tags/pull/6)) 157 | 158 | 159 | 160 | ## dbt-snowflake-query-tags 1.1.2 - February 13, 2023 161 | 162 | ### Features 163 | 164 | - Support dispatch order for macro configuration ([#2](https://github.com/get-select/dbt-snowflake-query-tags/pull/2)) 165 | 166 | ### Contributors 167 | - [@robscriva](https://github.com/robscriva) (Features) 168 | 169 | 170 | ## dbt-snowflake-query-tags 1.1.1 - February 12, 2023 171 | 172 | ### Fixes 173 | 174 | - Fix refs list ([#4](https://github.com/get-select/dbt-snowflake-query-tags/pull/4)) 175 | 176 | 177 | 178 | ## dbt-snowflake-query-tags 1.1.0 - February 11, 2023 179 | 180 | ### Features 181 | 182 | - Add node refs to tag ([#1](https://github.com/get-select/dbt-snowflake-query-tags/pull/1)) 183 | 184 | 185 | 186 | ## dbt-snowflake-query-tags 1.0.0 - February 08, 2023 187 | 188 | ### Features 189 | 190 | - Initial release 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dbt-snowflake-query-tags 2 | 3 | From the [SELECT](https://select.dev) team, a dbt package to automatically tag dbt-issued queries with informative metadata. This package uses both query comments and query tagging. 4 | 5 | An example query comment contains: 6 | 7 | ```json 8 | { 9 | "dbt_snowflake_query_tags_version": "2.3.2", 10 | "app": "dbt", 11 | "dbt_version": "1.4.0", 12 | "project_name": "my_project", 13 | "target_name": "dev", 14 | "target_database": "dev", 15 | "target_schema": "dev", 16 | "invocation_id": "4ffa20a1-5d90-4a27-a58a-553bb6890f25", 17 | "node_refs": [ 18 | "model_b", 19 | "model_c" 20 | ], 21 | "node_name": "model_a", 22 | "node_alias": "model_a", 23 | "node_package_name": "my_project", 24 | "node_original_file_path": "models/model_a.sql", 25 | "node_database": "dev", 26 | "node_schema": "dev", 27 | "node_id": "model.my_project.model_a", 28 | "node_resource_type": "model", 29 | "node_tags": ["tag_1", "tag_2"], 30 | "node_meta": {"owner": "@alice", "model_maturity": "in dev"}, 31 | "materialized": "incremental", 32 | "full_refresh": false, 33 | "which": "run" 34 | 35 | -- dbt Cloud only 36 | "dbt_cloud_project_id": "146126", 37 | "dbt_cloud_job_id": "184124", 38 | "dbt_cloud_run_id": "107122910", 39 | "dbt_cloud_run_reason_category": "other", 40 | "dbt_cloud_run_reason": "Kicked off from UI by niall@select.dev", 41 | } 42 | ``` 43 | 44 | Query tags are used solely for attaching the `is_incremental` flag, as this isn't available to the query comment: 45 | 46 | ```json 47 | { 48 | "dbt_snowflake_query_tags_version": "2.3.2", 49 | "app": "dbt", 50 | "is_incremental": true 51 | } 52 | ``` 53 | 54 | ## Quickstart 55 | 56 | 1. Add this package to your `packages.yml` file, then install it with `dbt deps`. 57 | 58 | ```yaml 59 | packages: 60 | - package: get-select/dbt_snowflake_query_tags 61 | version: [">=2.0.0", "<3.0.0"] 62 | ``` 63 | 64 | 2. Adding the query tags 65 | 66 | Option 1: If running dbt < 1.2, create a folder named `macros` in your dbt project's top level directory (if it doesn't exist). Inside, make a new file called `query_tags.sql` with the following content: 67 | 68 | ```sql 69 | {% macro set_query_tag() -%} 70 | {% do return(dbt_snowflake_query_tags.set_query_tag()) %} 71 | {% endmacro %} 72 | 73 | {% macro unset_query_tag(original_query_tag) -%} 74 | {% do return(dbt_snowflake_query_tags.unset_query_tag(original_query_tag)) %} 75 | {% endmacro %} 76 | ``` 77 | 78 | Option 2: If running dbt >= 1.2, simply configure the dispatch search order in `dbt_project.yml`. 79 | 80 | ```yaml 81 | dispatch: 82 | - macro_namespace: dbt 83 | search_order: 84 | - 85 | - dbt_snowflake_query_tags 86 | - dbt 87 | ``` 88 | 89 | 3. To configure the query comments, add the following config to `dbt_project.yml`. 90 | 91 | ```yaml 92 | query-comment: 93 | comment: '{{ dbt_snowflake_query_tags.get_query_comment(node) }}' 94 | append: true # Snowflake removes prefixed comments. 95 | ``` 96 | 97 | That's it! All dbt-issued queries will now be tagged. 98 | 99 | ## Adding additional metadata 100 | 101 | ### Query comments 102 | 103 | #### Meta and tag model configs 104 | 105 | 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. 106 | 107 | #### 'extra' kwarg 108 | 109 | 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: 110 | 111 | ```yaml 112 | query-comment: 113 | comment: '{{ dbt_snowflake_query_tags.get_query_comment(node, extra={"run_started_at": builtins.run_started_at | string }) }}' 114 | append: true # Snowflake removes prefixed comments. 115 | ``` 116 | 117 | #### Adding env vars to query comments 118 | 119 | Here's an example of how you can add environment variables into the query comment: 120 | 121 | ```sql 122 | query-comment: 123 | comment: > 124 | {{ dbt_snowflake_query_tags.get_query_comment( 125 | node, 126 | extra={ 127 | 'CI_PIPELINE_ID': env_var('CI_PIPELINE_ID'), 128 | 'CI_JOB_NAME': env_var('CI_JOB_NAME'), 129 | 'CI_COMMIT_REF_NAME': env_var('CI_COMMIT_REF_NAME'), 130 | 'CI_RUNNER_TAGS': env_var('CI_RUNNER_TAGS') 131 | } 132 | ) }} 133 | append: true # Snowflake removes prefixed comments. 134 | ``` 135 | 136 | ### Query tags 137 | 138 | To extend the information added in the query tags, there are a few options: 139 | 140 | #### Model config 141 | 142 | Set the [query_tag](https://docs.getdbt.com/reference/resource-configs/snowflake-configs#query-tags) config value to a mapping type. Example: 143 | 144 | Model (works for dbt Core) 145 | ```sql 146 | {{ config( 147 | query_tag = {'team': 'data'} 148 | ) }} 149 | 150 | select ... 151 | ``` 152 | 153 | or (works for dbt Core and Fusion) 154 | ```sql 155 | {{ config( 156 | query_tag = "{'team': 'data'}" 157 | ) }} 158 | 159 | select ... 160 | ``` 161 | 162 | Results in the following query tag. The additional information is added by this package. 163 | ``` 164 | '{"team": "data", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.2", "is_incremental": true}' 165 | ``` 166 | 167 | Note that using a non-mapping type in the `query_tag` config will result in a warning, and the config being ignored. 168 | 169 | Model 170 | ```sql 171 | {{ config( 172 | query_tag = 'data team' 173 | ) }} 174 | 175 | select ... 176 | ``` 177 | 178 | Warning: 179 | ``` 180 | 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. 181 | ``` 182 | 183 | #### Profiles.yml 184 | 185 | Additionally, you can set the `query_tag` value in the `profiles.yml`. This must be a valid mapping, not a string. 186 | 187 | profiles.yml 188 | ```yml 189 | default: 190 | outputs: 191 | dev: 192 | +query_tag: 193 | team: data 194 | ... 195 | target: dev 196 | ``` 197 | 198 | #### Environment variables 199 | 200 | Another option is to use the optional project variable `env_vars_to_query_tag_list` to provide a list of environment variables to pull query tag values from. 201 | 202 | Example: 203 | 204 | dbt_project.yml: 205 | ```yml 206 | vars: 207 | env_vars_to_query_tag_list: ['TEAM','JOB_NAME'] 208 | ``` 209 | 210 | Results in a final query tag of 211 | ``` 212 | '{"team": "data", "job_name": "daily", "app": "dbt", "dbt_snowflake_query_tags_version": "2.3.2", "is_incremental": true}' 213 | ``` 214 | 215 | #### 'extra' kwarg 216 | 217 | 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`. 218 | 219 | ``` 220 | {% macro set_query_tag() -%} 221 | {% do return(dbt_snowflake_query_tags.set_query_tag( 222 | extra={ 223 | 'custom_config_property': config.get('custom_config_property'), 224 | } 225 | )) %} 226 | {% endmacro %} 227 | 228 | {% macro unset_query_tag(original_query_tag) -%} 229 | {% do return(dbt_snowflake_query_tags.unset_query_tag(original_query_tag)) %} 230 | {% endmacro %} 231 | ``` 232 | 233 | ## Contributing 234 | 235 | ### Adding a CHANGELOG Entry 236 | We use changie to generate CHANGELOG entries. Note: Do not edit the CHANGELOG.md directly. Your modifications will be lost. 237 | 238 | Follow the steps to [install changie](https://changie.dev/guide/installation/) for your system. 239 | 240 | Once changie is installed and your PR is created, simply run these changie commands: 241 | 1. `changie new`: changie will walk you through the process of creating a changelog entry. 242 | 2. `changeie batch x.x.x` where x.x.x is the new version needed. You can chech the `.changes` folder to know the next version number. 243 | 3. `changie merge` 244 | 245 | Next, update `dbt_project.yaml` with the new version number. 246 | --------------------------------------------------------------------------------