Skip to content

Commit 53cd1a2

Browse files
jeremyyeobenc-db
andauthored
feat: Add tagging methods to snapshot (#1192)
<!-- Please review our pull request review process in CONTRIBUTING.md before your proceed. --> Resolves #1187 <!--- Include the number of the issue addressed by this PR above if applicable. Example: resolves #1234 Please review our pull request review process in CONTRIBUTING.md before your proceed. --> ### Description Add checking the `databricks_tags` config on snapshots and also apply them. With this change, the following snapshot definition: ```yaml # models/snapshots.yml snapshots: - name: yet_another_snap relation: ref('foo') config: strategy: check check_cols: all unique_key: id databricks_tags: some_key: some_value ``` Results in the tag being applied, e.g: ```sh $ dbt snapshot ... 03:31:23 On snapshot.analytics.yet_another_snap: /* {"app": "dbt", "dbt_version": "1.10.11", "dbt_databricks_version": "1.10.12", "databricks_sql_connector_version": "4.0.5", "profile_name": "all", "target_name": "db", "node_id": "snapshot.analytics.yet_another_snap"} */ merge into `dev`.`dbt_jyeo_prod`.`yet_another_snap` as DBT_INTERNAL_DEST using `yet_another_snap__dbt_tmp` as DBT_INTERNAL_SOURCE on DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id when matched and DBT_INTERNAL_DEST.dbt_valid_to is null and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete') then update set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to when not matched and DBT_INTERNAL_SOURCE.dbt_change_type = 'insert' then insert * ; 03:31:23 Databricks adapter: Cursor(session-id=01f099c0-197e-13b4-a02e-59b9c166a0cd, command-id=01f099c0-1c49-1cc0-9c79-34ee79b10d49) - Closing 03:31:26 SQL status: OK in 2.530 seconds 03:31:26 Databricks adapter: Cursor(session-id=01f099c0-197e-13b4-a02e-59b9c166a0cd, command-id=01f099c0-1c80-1c98-b0a1-941bd19f6f85) - Closing 03:31:26 Applying tags to relation {'some_key': 'some_value'} 03:31:26 Writing runtime sql for node "snapshot.analytics.yet_another_snap" 03:31:26 Using databricks connection "snapshot.analytics.yet_another_snap" 03:31:26 On snapshot.analytics.yet_another_snap: /* {"app": "dbt", "dbt_version": "1.10.11", "dbt_databricks_version": "1.10.12", "databricks_sql_connector_version": "4.0.5", "profile_name": "all", "target_name": "db", "node_id": "snapshot.analytics.yet_another_snap"} */ ALTER table `dev`.`dbt_jyeo_prod`.`yet_another_snap` SET TAGS ( 'some_key' = 'some_value' ) 03:31:26 SQL status: OK in 0.540 seconds 03:31:26 Databricks adapter: Cursor(session-id=01f099c0-197e-13b4-a02e-59b9c166a0cd, command-id=01f099c0-1e01-1877-a38d-036b87e44c45) - Closing 03:31:26 Applying DROP to: `yet_another_snap__dbt_tmp` 03:31:26 Using databricks connection "snapshot.analytics.yet_another_snap" 03:31:26 On snapshot.analytics.yet_another_snap: /* {"app": "dbt", "dbt_version": "1.10.11", "dbt_databricks_version": "1.10.12", "databricks_sql_connector_version": "4.0.5", "profile_name": "all", "target_name": "db", "node_id": "snapshot.analytics.yet_another_snap"} */ DROP VIEW IF EXISTS `yet_another_snap__dbt_tmp` 03:31:27 SQL status: OK in 0.470 seconds 03:31:27 Databricks adapter: Cursor(session-id=01f099c0-197e-13b4-a02e-59b9c166a0cd, command-id=01f099c0-1e57-1f95-b68b-45ebe2eccfbb) - Closing 03:31:27 On snapshot.analytics.yet_another_snap: Close 03:31:27 Databricks adapter: Connection(session-id=01f099c0-197e-13b4-a02e-59b9c166a0cd) - Closing 03:31:27 1 of 1 OK snapshotted dbt_jyeo_prod.yet_another_snap ........................... [OK in 9.54s] ``` ### Checklist - [x] I have run this code in development and it appears to resolve the stated issue - [x] This PR includes tests, or tests are not required/relevant for this PR - [x] I have updated the `CHANGELOG.md` and added information about my change to the "dbt-databricks next" section. --------- Co-authored-by: Ben Cassell <[email protected]>
1 parent 0b80e13 commit 53cd1a2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix issue causing MV/STs to always trigger as having their config changed ([1181](http://github.com/databricks/dbt-databricks/pull/1181))
66
- Fix pydantic v2 deprecation warning "Valid config keys have changed in V2" (thanks @Korijn!) ([1194](https://github.com/databricks/dbt-databricks/pull/1194))
7+
- Fix snapshots not applying databricks_tags config ([1192](https://github.com/databricks/dbt-databricks/pull/1192))
78

89
## dbt-databricks 1.10.12 (September 8, 2025)
910

dbt/include/databricks/macros/materializations/snapshot.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{%- set unique_key = config.get('unique_key') %}
66
{%- set file_format = config.get('file_format', 'delta') -%}
77
{%- set grant_config = config.get('grants') -%}
8+
{%- set tags = config.get('databricks_tags') -%}
89

910
{% set target_relation_exists, target_relation = databricks__get_or_create_relation(
1011
database=model.database,
@@ -100,6 +101,11 @@
100101
{% endcall %}
101102

102103
{% set should_revoke = should_revoke(target_relation_exists, full_refresh_mode=False) %}
104+
105+
{%- if tags -%}
106+
{%- do apply_tags(target_relation, tags) -%}
107+
{%- endif -%}
108+
103109
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %}
104110

105111
{% do persist_docs(target_relation, model) %}

0 commit comments

Comments
 (0)