2323from dbt .adapters .base .meta import available
2424from dbt .adapters .base .relation import BaseRelation
2525from dbt .adapters .capability import Capability , CapabilityDict , CapabilitySupport , Support
26+ from dbt .adapters .catalogs import CatalogRelation
2627from dbt .adapters .contracts .connection import AdapterResponse , Connection
2728from dbt .adapters .contracts .relation import RelationConfig , RelationType
28- from dbt .adapters .databricks import constraints
29+ from dbt .adapters .databricks import constants , constraints , parse_model
2930from dbt .adapters .databricks .behaviors .columns import (
3031 GetColumnsBehavior ,
3132 GetColumnsByDescribe ,
3233 GetColumnsByInformationSchema ,
3334)
35+ from dbt .adapters .databricks .catalogs import (
36+ DatabricksCatalogRelation ,
37+ HiveMetastoreCatalogIntegration ,
38+ UnityCatalogIntegration ,
39+ )
3440from dbt .adapters .databricks .column import DatabricksColumn
3541from dbt .adapters .databricks .connections import DatabricksConnectionManager
3642from dbt .adapters .databricks .global_state import GlobalState
@@ -180,6 +186,10 @@ class DatabricksAdapter(SparkAdapter):
180186 }
181187 )
182188
189+ CATALOG_INTEGRATIONS = [
190+ HiveMetastoreCatalogIntegration ,
191+ UnityCatalogIntegration ,
192+ ]
183193 CONSTRAINT_SUPPORT = constraints .CONSTRAINT_SUPPORT
184194
185195 get_column_behavior : GetColumnsBehavior
@@ -196,6 +206,9 @@ def __init__(self, config: Any, mp_context: SpawnContext) -> None:
196206 except CompilationError :
197207 pass
198208
209+ self .add_catalog_integration (constants .DEFAULT_UNITY_CATALOG )
210+ self .add_catalog_integration (constants .DEFAULT_HIVE_METASTORE_CATALOG )
211+
199212 @property
200213 def _behavior_flags (self ) -> list [BehaviorFlag ]:
201214 return [USE_INFO_SCHEMA_FOR_COLUMNS , USE_USER_FOLDER_FOR_PYTHON , USE_MATERIALIZATION_V2 ]
@@ -205,20 +218,18 @@ def update_tblproperties_for_iceberg(
205218 self , config : BaseConfig , tblproperties : Optional [dict [str , str ]] = None
206219 ) -> dict [str , str ]:
207220 result = tblproperties or config .get ("tblproperties" , {})
208- if config .get ("table_format" ) == TableFormat .ICEBERG :
221+
222+ catalog_relation : DatabricksCatalogRelation = self .build_catalog_relation (config .model ) # type:ignore
223+ if catalog_relation .table_format == constants .ICEBERG_TABLE_FORMAT :
209224 if self .compare_dbr_version (14 , 3 ) < 0 :
210225 raise DbtConfigError ("Iceberg support requires Databricks Runtime 14.3 or later." )
211- if config .get ("file_format" , "delta" ) != "delta" :
212- raise DbtConfigError (
213- "When table_format is 'iceberg', cannot set file_format to other than delta."
214- )
215226 if config .get ("materialized" ) not in ("incremental" , "table" , "snapshot" ):
216227 raise DbtConfigError (
217228 "When table_format is 'iceberg', materialized must be 'incremental'"
218229 ", 'table', or 'snapshot'."
219230 )
220- result [ "delta.enableIcebergCompatV2" ] = "true"
221- result [ "delta.universalFormat.enabledFormats" ] = "iceberg"
231+ result . update ( catalog_relation . iceberg_table_properties )
232+
222233 return result
223234
224235 @available .parse (lambda * a , ** k : 0 )
@@ -820,6 +831,26 @@ def is_cluster(self) -> bool:
820831 def clean_sql (self , sql : str ) -> str :
821832 return SqlUtils .clean_sql (sql )
822833
834+ @available
835+ def build_catalog_relation (self , model : RelationConfig ) -> Optional [CatalogRelation ]:
836+ """
837+ Builds a relation for a given configuration.
838+
839+ This method uses the provided configuration to determine the appropriate catalog
840+ integration and config parser for building the relation. It defaults to the built-in Delta
841+ catalog if none is provided in the configuration for backward compatibility.
842+
843+ Args:
844+ model (RelationConfig): `config.model` (not `model`) from the jinja context
845+
846+ Returns:
847+ Any: The relation object generated through the catalog integration and parser
848+ """
849+ if catalog := parse_model .catalog_name (model ):
850+ catalog_integration = self .get_catalog_integration (catalog )
851+ return catalog_integration .build_relation (model )
852+ return None
853+
823854
824855@dataclass (frozen = True )
825856class RelationAPIBase (ABC , Generic [DatabricksRelationConfig ]):
0 commit comments