Skip to content

feat: add catalog_database support for Unity catalogs (catalogs.yml v2)#1590

Merged
sd-db merged 12 commits into
databricks:mainfrom
aahel:catalog-database-support
Jul 19, 2026
Merged

feat: add catalog_database support for Unity catalogs (catalogs.yml v2)#1590
sd-db merged 12 commits into
databricks:mainfrom
aahel:catalog-database-support

Conversation

@aahel

@aahel aahel commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Resolves #

Description

Adds catalog_database support for Unity catalogs in catalogs.yml v2, so a model can be routed to an explicit physical Unity catalog independent of the dbt catalog label (name). This mirrors the Fusion implementation (dbt-labs/fs#11436): databricks__generate_database_name now returns catalog_relation.catalog_database first, taking precedence over the model database config and catalog_name.

Precedence (matches Fusion): catalog_database > model database config > catalog_name > target.database.

Config (v2 catalogs.yml):

catalogs:
  - name: my_catalog          # dbt label (models reference this via catalog_name)
    type: unity
    table_format: iceberg
    config:
      databricks:
        catalog_database: prod_catalog   # physical Unity catalog

Changes

  • DatabricksCatalogRelation: add catalog_database field.
  • UnityCatalogIntegration: read the first-class catalog_database field (surfaced on the config by the base CatalogIntegration from the v2 catalogs.yml config block) and carry it onto the relation. Hive-metastore is unaffected (no catalog layer).
  • databricks__generate_database_name: prefer catalog_database, mirroring fs.
  • No dbt-adapters pin bump: catalog_database is read via getattr(config, "catalog_database", None) and the relation always carries the field, so on dbt-adapters <1.24.4 (which has no catalog_database on the catalog config) it resolves to None — a graceful no-op, no crash. It's honored on dbt-adapters>=1.24.4.
  • Unit tests (integration + macro precedence) + CHANGELOG.

No behavior change for existing projects that don't set catalog_database.

Requirements: catalog_database takes effect only under v2 catalogs — needs dbt-core ≥ 1.12 (use_catalogs_v2, which triggers bridge_v2_catalog) and dbt-adapters ≥ 1.24.4 (bridge surfaces catalog_database onto the catalog config). Below that it resolves to None (graceful no-op). Note: dbt-core's own CatalogWriteIntegrationConfig does not carry catalog_database even on 1.13.0a1, so the value flows only through the dbt-adapters v2 bridge — the v1 write_integrations path can't carry it.

⚠️ dbt-core pin: pyproject.toml currently pins dbt-core <1.11.13, which excludes 1.12 — so the feature can't be exercised with the adapter's current pin. Merging as-is lands it dormant/forward-looking; activating it needs a dbt-core pin bump to allow ≥1.12 (separate/maintainer decision).

Testing: unit-tested — the catalog_database config→integration→relation flow (test_catalogs_v2.py, incl. a graceful-degradation case for adapters without the field) and the macro precedence via a rendered databricks__generate_database_name (test_generate_database_name.py: catalog_database > model database > catalog_name > target.database). End-to-end dbt parse on a v2-capable dbt-core is not run here (the pin caps below 1.12).

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.
  • [Optional] I have run /dbt-databricks-pr-ready (AI agent skill in .claude/skills/) and addressed its merge-readiness feedback

Route models to an explicit physical Unity catalog via catalog_database,
decoupled from the dbt catalog label. Mirrors the Fusion (fs) implementation:
generate_database_name returns catalog_relation.catalog_database first, taking
precedence over the model database config and catalog_name.

- DatabricksCatalogRelation: add catalog_database field
- UnityCatalogIntegration: carry catalog_database onto the relation
- databricks__generate_database_name: prefer catalog_database
- bump dbt-adapters lower bound to 1.24.5 (base catalog_database support)
- unit tests + changelog
@aahel
aahel requested review from jprakash-db and sd-db as code owners July 15, 2026 10:08
aahel added 8 commits July 15, 2026 15:43
Renders the jinja macro to verify catalog_database > model database >
catalog_name > target.database (the precedence added for catalog_database).
…ogs path)

Manual testing (dbt parse + manifest) showed catalog_database was ignored: on
the dbt-core versions dbt-databricks runs on (1.11.x), catalogs.yml write-
integration extras arrive via adapter_properties, and CatalogWriteIntegrationConfig
has no catalog_database field, so config.catalog_database was always None. Read it
from adapter_properties (like location_root/use_uniform), falling back to the base
attribute for newer dbt-core. Verified a model now routes to catalog_database over
its own database config and catalog_name.
…er_properties

catalog_database is a v2 catalogs feature; the base CatalogIntegration surfaces it
on the config from the catalogs.yml config block. Read config.catalog_database (via
getattr for version-safety) rather than adapter_properties. On dbt-core without v2
catalog support it resolves to None (no-op), which is expected for a v2 feature.
…lly on <1.24.4

Revert pyproject/requirements.lowest-direct/uv.lock back to dbt-adapters>=1.22.0.
No runtime guard needed: UnityCatalogIntegration reads getattr(config,
'catalog_database', None) and the relation always carries the field, so on
dbt-adapters <1.24.4 (no catalog_database on the config) it resolves to None and
catalog_database is a graceful no-op. Add a regression test with a config lacking
the attribute, and note the 1.24.4 requirement in the CHANGELOG instead of pinning.
@sd-db sd-db changed the title Add catalog_database support for Unity catalogs (catalogs.yml v2) feat: add catalog_database support for Unity catalogs (catalogs.yml v2) Jul 16, 2026
Comment thread dbt/adapters/databricks/catalogs/_unity.py Outdated
@@ -19,9 +19,20 @@ class _Config:
table_format: Optional[str] = "iceberg"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note for later to add functional tests once support for dbt-core v1.12 is added in the adapter

Comment thread CHANGELOG.md Outdated

@sd-db sd-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes look good, thx for the PR !!

@sd-db
sd-db merged commit de15722 into databricks:main Jul 19, 2026
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.

2 participants