Skip to content

perf: apply only new or changed databricks_tags on table re-runs - #1572

Closed
sd-db wants to merge 5 commits into
mainfrom
fix/issue-1308-table-tags-reapplied
Closed

perf: apply only new or changed databricks_tags on table re-runs#1572
sd-db wants to merge 5 commits into
mainfrom
fix/issue-1308-table-tags-reapplied

Conversation

@sd-db

@sd-db sd-db commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

Table rebuilds and incremental full-refresh replacements reapply configured table and column tags even when those tags already match the server. This adds unnecessary ALTER … SET TAGS statements, particularly for models with many tagged columns.

Root cause

Table rebuilds and incremental full-refresh replacements bypass the normal incremental ALTER changeset flow. Their creation paths therefore did not reuse the existing TagsConfig.get_diff and ColumnTagsConfig.get_diff comparisons.

Fix

  • Share reconcile_tags across the V1 and V2 Table and Incremental full-refresh paths.
  • After an in-place table replacement, compare configured tags with the tags retained on the server and skip application when they match.
  • Expose one tag-only adapter helper, get_table_replacement_tag_changes, so Jinja can reuse the Python processors and component diffs without fetching unrelated relation configuration.
  • Fetch only configured tag categories; models with no tags skip tag metadata reads entirely.
  • Apply full configured tags for fresh creates, drop-and-recreates, shallow-clone rebuilds, and safe staging replacements. An existing relation alone is not sufficient to enable the diff.
  • Leave normal incremental updates on their existing changeset path, including incremental_apply_config_changes.

This PR wires replacement paths into the existing component diffs; it does not introduce per-key filtering. At this head, a changed table tag can reapply the desired table-tag map, and a changed column can reapply that column's desired tags. Finer-grained table and column tag diffs are handled separately in #1667 and #1668.

Only tags are in scope; reconciliation of other metadata after replacement is unchanged.

Validation

  • Full unit suite: 1,356 passed, 4 skipped.
  • Code-quality and all-files pre-commit checks passed.
  • Adapter and macro unit tests cover conditional metadata reads and full-versus-diff tag application.
  • Eight live Unity Catalog SQL warehouse cases passed: Table and Incremental full-refresh, V1 and V2, with table and column tags. Each case queries information_schema after creation, unchanged full-refresh, and changed full-refresh to verify the stored tag values.
  • Additional tag lifecycle, shallow-clone, and normal incremental column-tag tests passed during development.

Live replacement validation used Delta tables; managed Iceberg behavior was not verified.

Resolves #1308

@sd-db
sd-db requested a review from jprakash-db as a code owner July 1, 2026 12:21
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  impl.py 1161, 1198
Project Total  

This report was generated by python-coverage-comment-action

sd-db added 2 commits August 9, 2026 06:45
Address review gaps on the table tag-diff change:

- Assert a *changed* tag value still reaches the server on a re-run, for
  both table- and column-level tags. This is the diff path's one real
  failure mode and was previously uncovered; the existing tests only
  assert whether a metadata fetch occurred.
- Add a v2 `create_table_at` case for table-level tags. v2 coverage was
  column-tags only, and `use_materialization_v2` defaults to false, so the
  unmarked classes all exercise v1.
- Make `TestTableDropRecreateAppliesAllTags` rerun-safe. It rewrites a
  model via `write_file`, so without the mixin a `--reruns` retry inherits
  the converted table and stops testing view->table conversion.

Also link the PR in the changelog entry and describe the diff's gating
condition rather than naming file formats: `resolve_file_format` maps
`table_format='iceberg'` to delta or parquet, so it does not return the
literal 'iceberg' the gate tests for.
Resolves a conflict in `table.sql` between this branch's `replaced_in_place`
refactor and #1592, which added `is_shallow_clone` to the two drop conditions
that `replaced_in_place` negates.

Since a shallow clone's table type cannot be changed in place, it must be
dropped and recreated -- so it is not replaced in place and inherits no tags.
Folded the term into the predicate rather than into the drop sites, keeping
both as `not replaced_in_place`:

  replaced_in_place = existing_relation
      and not existing_relation.is_shallow_clone
      and existing_relation.type == 'table'
      and existing_relation.can_be_replaced
      and adapter.resolve_file_format(config) in ('delta', 'iceberg')

`can_be_replaced` alone does not cover this: it tests relation type plus
delta/iceberg provider, so a shallow clone of a delta table passes it.

Add `TestRebuildOverShallowCloneAppliesAllTags`, which covers the interaction
both changes touch: rebuilding a tagged table over a shallow clone must drop
the clone and apply all tags to the fresh table. Without the `is_shallow_clone`
term it fails on `MANAGED_SHALLOW_CLONE != MANAGED` -- i.e. it guards #1592's
fix, not only the tag diff.

Also move this branch's changelog entry to the 1.12.4 (TBD) section; the
automatic merge placed it under the already-released 1.12.2 heading.
@sd-db sd-db changed the title fix: apply only new or changed databricks_tags on table re-runs perf: apply only new or changed databricks_tags on table re-runs Sep 9, 2026
@sd-db

sd-db commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

/integration-test

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Integration tests dispatched for PR #1572 by @sd-db. Testing commit aa94d84. Track progress in the Actions tab.

@sd-db
sd-db requested a review from saishreeeee as a code owner September 9, 2026 06:37
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Integration results for PR #1572 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success · Shard coverage ✅ success

Run details.

@sd-db

sd-db commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this for now. The extra information_schema reads could cost more than reapplying the tags, and we haven’t measured a clear win. I’d rather keep Table rebuilds and incremental full-refresh simple.

#1667 and #1668 are separate—they improve tag diffs where we already use changesets.


This comment was generated with GitHub MCP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Databricks_tags are set every run

2 participants