Databricks and Apache Iceberg
dbt supports materializing Iceberg tables in Unity Catalog in two ways:
- Simplest: The model config
table_format = 'iceberg'instructs dbt to materialize this model as an Iceberg table in Unity Catalog - Extensible: Define an Iceberg catalog in
catalogs.ymland configure this model withcatalog_name
dbt supports creating Iceberg tables for two Databricks materializations:
Databricks Iceberg support
Databricks is built on Delta Lake and stores data in the Delta table format.
Databricks supports two methods for creating Iceberg tables in its data catalog, Unity Catalog:
- Creating Unity Catalog managed Iceberg tables. Databricks Runtime 16.4 LTS and later support this feature.
- Enabling Iceberg reads on Delta tables. These tables still use the Delta file format, but generate both Delta and Iceberg-compatible metadata. Databricks Runtime 14.3 LTS and later support this feature.
dbt supports both creating managed Iceberg tables and Iceberg-enabled Delta tables (formerly UniForm). The behavior flag use_managed_iceberg determines whether dbt creates a managed Iceberg table or a Delta table.
External Iceberg compute engines can read from and write to these Iceberg tables using Unity Catalog's Iceberg REST API endpoint. However, Databricks only has limited support for reading from external Iceberg catalogs (and externally managed Iceberg tables) through Databricks catalog federation (configured outside of dbt).
dbt doesn't yet support enabling Iceberg v3 on managed Iceberg tables.
External tables
dbt also supports creating externally-managed Iceberg tables using the model configuration location_root. Databricks' DDL for creating tables requires a fully qualified location. dbt defines this parameter on the user's behalf to streamline usage and enforce basic isolation of table data:
- When you set a
location_rootstring, dbt generates alocationstring of the form:{{ location_root }}/{{ model_name }}. - If you set the configuration option
include_full_name_in_pathtotrue, dbt generates alocationstring of the form{{ location_root }}/{{ database_name}}/{{ schema_name }}/{{ model_name }}.
In dbt v2, you may set location_root within the catalog definition in catalogs.yml, under config.databricks (in the new catalog spec) or adapter_properties (in the old catalog spec).
Catalogs
Configure catalogs in order to:
- Define multiple configurations for Databricks-managed Iceberg tables within one catalog
- Support cross-platform Mesh
Notes:
- Every Databricks catalog may optionally configure
table_format. By default, this is set toicebergforcatalog_type=unity, anddefaultforhive_metastore. - On Databricks,
catalog_nametakes precedence over thecatalogconfig when determining the model's top-level namespace.
Configure catalog integration for Iceberg tables
- Create a
catalogs.ymlat the top level of your dbt project. An example of Unity Catalog as the catalog:
- New spec
- Old spec
catalogs:
- name: unity_catalog
type: unity
table_format: iceberg # optional
config:
databricks:
# optional
location_root: s3://cloud-storage-uri
catalogs:
- name: unity_catalog
active_write_integration: unity_catalog_integration
write_integrations:
- name: unity_catalog_integration
table_format: iceberg
catalog_type: unity
file_format: delta
adapter_properties:
location_root: s3://cloud-storage-uri
- Add the
catalog_nameconfig parameter in either a config block (inside the .sql model file), properties YAML file (model folder), or your project YAML file (dbt_project.yml).
An example of iceberg_model.sql:
{{
config(
materialized = 'table',
catalog_name = 'unity_catalog'
)
}}
select * from {{ ref('jaffle_shop_customers') }}
- Execute the dbt model with a
dbt run -s iceberg_model.
Was this page helpful?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.