Connecting Databricks Unity Catalog to the Lakehouse runtime catalog
lets you query remote Apache Iceberg tables without copying or
migrating them.

In this tutorial, you use BigQuery SQL in a retail scenario to
join an Iceberg table named `dim_products` in Databricks
Unity Catalog with a local `fact_sales` table. You then calculate product gross
margins across clouds. The steps assume familiarity with Databricks Unity
Catalog, BigQuery, and SQL.

## Objectives

- Create a sample Iceberg table in Databricks Unity Catalog and grant access to a Databricks service principal.
- Create a federated catalog in the Lakehouse runtime catalog by using OpenID Connect (OIDC) token federation.
- Query the federated Databricks Unity Catalog table from BigQuery and join it with a local BigQuery table in a SQL view.

## Costs


In this document, you use the following billable components of Google Cloud:


- [Lakehouse](https://cloud.google.com/products/lakehouse/pricing)
- [BigQuery](https://cloud.google.com/bigquery/pricing)
- [Cloud Storage](https://cloud.google.com/storage/pricing) (if your Databricks external location uses a `gs://` bucket)


To generate a cost estimate based on your projected usage,
use the [pricing calculator](https://docs.cloud.google.com/products/calculator).
New Google Cloud users might be eligible for a [free trial](https://docs.cloud.google.com/free).

<br />

When you finish the tasks that are described in this document, you can avoid
continued billing by deleting the resources that you created. For more information, see
[Clean up](https://docs.cloud.google.com/lakehouse/docs/query-databricks-unity-catalog-tutorial.md.txt#clean-up).

This tutorial also uses compute, storage, and data transfer (egress) in your
Databricks workspace and remote object storage. Databricks and your cloud
storage provider bill you for these resources.

## Before you begin

1. In the Google Cloud console, on the project selector page, select or [create a
   Google Cloud
   project](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects).

   [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)

   > [!NOTE]
   > **Note:** If you don't plan to keep the resources that you create in this tutorial, create a new project instead of selecting an existing project. After you finish, you can delete the project to remove all resources associated with it.

2. [Verify that billing is enabled](https://docs.cloud.google.com/billing/docs/how-to/verify-billing-enabled.md.txt#console)
   for your Google Cloud project.

3. Your Databricks environment must meet the following requirements:

   - A Databricks workspace with Databricks Unity Catalog enabled and an external location on [Amazon Web Services (AWS)](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-external-locations), [Microsoft Azure](https://learn.microsoft.com/azure/databricks/sql/language-manual/sql-ref-external-locations), or [Google Cloud](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-external-locations). Catalogs that use default workspace storage aren't supported.
   - Serverless compute enabled in your Databricks workspace to create managed Iceberg tables. For requirements, see the Databricks documentation for [AWS](https://docs.databricks.com/aws/en/tables/iceberg), [Azure](https://learn.microsoft.com/azure/databricks/tables/iceberg), or [Google Cloud](https://docs.databricks.com/gcp/en/tables/iceberg).
   - A Databricks SQL warehouse (for instructions, see the Databricks documentation for [AWS](https://docs.databricks.com/aws/en/compute/sql-warehouse), [Azure](https://learn.microsoft.com/azure/databricks/compute/sql-warehouse), or [Google Cloud](https://docs.databricks.com/gcp/en/compute/sql-warehouse)) or a compute cluster running Databricks Runtime 16.4 LTS or later.
   - Permissions to manage catalogs, schemas, and service principals in your Databricks workspace and account console.
4. Confirm with your Databricks metastore administrator that external data
   access is enabled on your Databricks Unity Catalog metastore. For
   instructions, see the Databricks documentation for
   [AWS](https://docs.databricks.com/aws/en/external-access/admin),
   [Azure](https://learn.microsoft.com/azure/databricks/external-access/admin),
   or
   [Google Cloud](https://docs.databricks.com/gcp/en/external-access/admin).

### Required roles


To get the permissions that
you need to complete the tasks in this tutorial,

ask your administrator to grant you the
following IAM roles on your project:

- Enable APIs: [Service Usage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageAdmin) (`roles/serviceusage.serviceUsageAdmin`)
- Create and manage federated catalogs in the Lakehouse runtime catalog: [](https://docs.cloud.google.com/iam/docs/roles-permissions/biglake.md.txt#biglake.admin)[BigLake Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/biglake.md.txt#biglake.admin) (`roles/biglake.admin`)
- Create and query datasets, tables, and views in BigQuery:
  - [BigQuery Data Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataEditor) (`roles/bigquery.dataEditor`)
  - [BigQuery Job User](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Prepare your environment

Activate Cloud Shell and prepare your environment:

1. In the Google Cloud console, activate Cloud Shell.

   [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)
2. In Cloud Shell, set the following environment variables:

   ```bash
   export PROJECT_ID=$(gcloud config get-value project)
   export REGION="us-central1"
   export FEDERATED_CATALOG_ID="databricks_retail_catalog"
   export BQ_DATASET_ID="retail_analytics"
   export UNITY_INSTANCE_NAME="UNITY_INSTANCE_NAME"
   export UNITY_CATALOG_NAME="UNITY_CATALOG_NAME"
   export UNITY_NAMESPACE="retail_db"
   ```

   Set `REGION` to the Google Cloud region closest to your Databricks
   storage (for example, `us-central1`), or the same region if your Databricks
   workspace is on Google Cloud.

   Replace the following:
   - `UNITY_INSTANCE_NAME`: your Databricks workspace hostname without the `https://` prefix, such as `dbc-a1b2c3d4-e5f6.cloud.databricks.com` (on AWS), `adb-1234567890123456.7.azuredatabricks.net` (on Azure), or `1234567890123456.7.gcp.databricks.com` (on Google Cloud).
   - `UNITY_CATALOG_NAME`: the name of your target catalog in Databricks Unity Catalog, such as `gcp_federation_catalog`.
3. Enable the following APIs, which provide access to BigQuery
   and to the Lakehouse runtime catalog:

   ```bash
   gcloud services enable \
       bigquery.googleapis.com \
       biglake.googleapis.com \
       --project="${PROJECT_ID}"
   ```

## Create an Iceberg table in Databricks Unity Catalog

Create a sample `dim_products` Iceberg table:

1. In your Databricks workspace, open the **SQL Editor** . For instructions, see
   the Databricks documentation for
   [AWS](https://docs.databricks.com/aws/en/sql/sql-editor),
   [Azure](https://learn.microsoft.com/azure/databricks/sql/sql-editor/),
   or
   [Google Cloud](https://docs.databricks.com/gcp/en/sql/sql-editor).

2. If you don't already have a catalog backed by an external storage location,
   create one:

   ```sql
   CREATE CATALOG IF NOT EXISTS UNITY_CATALOG_NAME
   MANAGED LOCATION 'EXTERNAL_STORAGE_URI';
   ```

   Replace the following:
   - `UNITY_CATALOG_NAME`: the name of your target catalog in Databricks Unity Catalog, such as `gcp_federation_catalog`.
   - `EXTERNAL_STORAGE_URI`: the URI of your external storage location, such as `s3://example-bucket/unity-catalog/`, `abfss://example-container@exampleaccount.dfs.core.windows.net/unity-catalog/`, or `gs://example-bucket/unity-catalog/`.
3. Create a schema named `retail_db` and the `dim_products` table, and insert
   sample product records:

   ```sql
   CREATE SCHEMA IF NOT EXISTS UNITY_CATALOG_NAME.retail_db;

   CREATE OR REPLACE TABLE UNITY_CATALOG_NAME.retail_db.dim_products (
     product_id STRING,
     product_name STRING,
     category STRING,
     brand STRING,
     unit_cost DOUBLE
   ) USING iceberg;

   INSERT INTO UNITY_CATALOG_NAME.retail_db.dim_products VALUES
     ('P101', 'Trail Running Shoes', 'Footwear', 'Cymbal Trail', 58.00),
     ('P102', 'Insulated Water Bottle', 'Accessories', 'Cymbal Gear', 12.50),
     ('P103', 'Ultralight Daypack', 'Gear', 'Cymbal Pack', 42.00),
     ('P104', 'Merino Wool Socks', 'Apparel', 'Cymbal Trail', 8.25);
   ```

## Configure a Databricks service principal

Create a Databricks service principal and grant it privileges to read your
target catalog and schema and to vend storage credentials:

1. Create a Databricks service principal (such as `lakehouse-federation-sp`)
   and copy its **Application ID** UUID. For instructions, see the Databricks
   documentation for
   [AWS](https://docs.databricks.com/aws/en/admin/users-groups/manage-service-principals),
   [Azure](https://learn.microsoft.com/azure/databricks/admin/users-groups/service-principals),
   or
   [Google Cloud](https://docs.databricks.com/gcp/en/admin/users-groups/service-principals).

2. In the Databricks **SQL Editor**, grant the service principal access to read
   the target catalog and schema and vend storage credentials:

   ```sql
   GRANT USE CATALOG ON CATALOG UNITY_CATALOG_NAME
     TO `SERVICE_PRINCIPAL_APPLICATION_ID`;

   GRANT USE SCHEMA, SELECT, EXTERNAL USE SCHEMA
     ON SCHEMA UNITY_CATALOG_NAME.retail_db
     TO `SERVICE_PRINCIPAL_APPLICATION_ID`;
   ```

   Replace `SERVICE_PRINCIPAL_APPLICATION_ID` with the
   Application ID UUID of your Databricks service principal. Keep the
   surrounding backticks.

## Create a federated catalog in the Lakehouse runtime catalog

Create a read-only federated catalog in the
Lakehouse runtime catalog and configure OIDC token federation so
Lakehouse can authenticate by using OIDC without storing static
secrets. For more information about Databricks token federation, see the
Databricks documentation for
[AWS](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-federation),
[Azure](https://learn.microsoft.com/azure/databricks/dev-tools/auth/oauth-federation),
or
[Google Cloud](https://docs.databricks.com/gcp/en/dev-tools/auth/oauth-federation):

1. In Cloud Shell, set an environment variable for the Application ID
   of your Databricks service principal. Then, create the catalog with
   cross-cloud caching enabled:

   ```bash
   export UNITY_SP_APP_ID="SERVICE_PRINCIPAL_APPLICATION_ID"

   gcloud biglake iceberg catalogs create ${FEDERATED_CATALOG_ID} \
       --project="${PROJECT_ID}" \
       --primary-location="${REGION}" \
       --catalog-type="federated" \
       --federated-catalog-type="unity" \
       --unity-service-principal-application-id="${UNITY_SP_APP_ID}" \
       --unity-instance-name="${UNITY_INSTANCE_NAME}" \
       --unity-catalog-name="${UNITY_CATALOG_NAME}" \
       --namespace-filters="${UNITY_NAMESPACE}" \
       --cross-cloud-cache="enabled"
   ```

   Replace `SERVICE_PRINCIPAL_APPLICATION_ID` with the
   Application ID UUID of your Databricks service principal.
2. Retrieve the numeric unique ID of the service account that the
   Lakehouse runtime catalog provisioned for your catalog:

   ```bash
   gcloud biglake iceberg catalogs describe ${FEDERATED_CATALOG_ID} \
       --project="${PROJECT_ID}" \
       --format='value(biglake-service-account-id)'
   ```

   Copy the ID from the command output.
3. In your Databricks account console, create a service principal federation
   policy with the following values:

   - **Issuer** : `https://accounts.google.com`.
   - **Subject**: the numeric unique ID from the preceding step.
   - **Audiences** : `https://accounts.cloud.databricks.com`. Use this exact value even if your Databricks workspace is on Azure or Google Cloud. Lakehouse uses this OIDC token audience for all clouds, so don't replace it with a cloud-specific hostname.

   For instructions, see the Databricks documentation for
   [AWS](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-federation-policy#workload-identity-federation),
   [Azure](https://learn.microsoft.com/azure/databricks/dev-tools/auth/oauth-federation-policy),
   or
   [Google Cloud](https://docs.databricks.com/gcp/en/dev-tools/auth/oauth-federation-policy).
4. In Cloud Shell, enable background metadata refresh on the federated
   catalog:

   ```bash
   gcloud biglake iceberg catalogs update ${FEDERATED_CATALOG_ID} \
       --project="${PROJECT_ID}" \
       --refresh-interval="300s"
   ```

## Verify background metadata refresh

Before you join tables across clouds, check that your federated catalog has
synchronized metadata from Databricks Unity Catalog and run a test query on
`dim_products`:

1. In Cloud Shell, inspect the federated catalog details:

   ```bash
   gcloud biglake iceberg catalogs describe ${FEDERATED_CATALOG_ID} \
       --project="${PROJECT_ID}"
   ```

   The output is similar to the following:

       ...
       federated-catalog-options:
         refresh-options:
           refresh-schedule:
             refresh-interval: 300s
           refresh-scope:
             namespace-filters:
             - retail_db
         refresh-status:
           end-time: '2026-03-01T12:05:12Z'
           start-time: '2026-03-01T12:05:08Z'
           status:
             message: Refresh completed. Check the audit logs for any namespace
               and table synchronization errors.
       ...

   In the `federated-catalog-options.refresh-status` field, confirm that
   `end-time` is populated, `status.message` reports completion, and no error
   `code` field appears. If the first refresh is still in progress, wait a few
   moments and rerun the command.
2. Confirm that the `retail_db` namespace is synchronized in the federated
   catalog:

   ```bash
   gcloud biglake iceberg namespaces list \
       --project="${PROJECT_ID}" \
       --catalog="${FEDERATED_CATALOG_ID}"
   ```

   The output is similar to the following:

       NAME                                                                             NAMESPACE-ID
       projects/example-project/catalogs/databricks_retail_catalog/namespaces/retail_db retail_db

3. Use BigQuery to query the federated `dim_products` table with
   the four-part P.C.N.T. (Project.Catalog.Namespace.Table) identifier:

   ```bash
   bq query \
       --project_id="${PROJECT_ID}" \
       --location="${REGION}" \
       --use_legacy_sql=false \
       "SELECT product_id, product_name, category, brand, unit_cost
        FROM \`${PROJECT_ID}.${FEDERATED_CATALOG_ID}.${UNITY_NAMESPACE}.dim_products\`
        ORDER BY product_id;"
   ```

   The output is similar to the following:

       +---+---+---+---+---+
       | product_id |      product_name      |  category   |    brand     | unit_cost |
       +---+---+---+---+---+
       | P101       | Trail Running Shoes    | Footwear    | Cymbal Trail |      58.0 |
       | P102       | Insulated Water Bottle | Accessories | Cymbal Gear  |      12.5 |
       | P103       | Ultralight Daypack     | Gear        | Cymbal Pack  |      42.0 |
       | P104       | Merino Wool Socks      | Apparel     | Cymbal Trail |      8.25 |
       +---+---+---+---+---+

## Join Databricks Unity Catalog data with BigQuery tables

To analyze revenue and gross margin across clouds, create a local sales
transaction table in BigQuery and join it with your
`dim_products` table from Databricks Unity Catalog:

1. In Cloud Shell, create a BigQuery dataset in the
   same region as your catalog in the Lakehouse runtime catalog:

   ```bash
   bq --location="${REGION}" mk --dataset "${PROJECT_ID}:${BQ_DATASET_ID}"
   ```
2. Create the `fact_sales` table in BigQuery and populate it
   with sample sales transactions:

   ```bash
   bq query \
       --project_id="${PROJECT_ID}" \
       --location="${REGION}" \
       --use_legacy_sql=false << EOF
   CREATE OR REPLACE TABLE \`${PROJECT_ID}.${BQ_DATASET_ID}.fact_sales\` (
     transaction_id STRING,
     sale_date DATE,
     product_id STRING,
     store_region STRING,
     quantity INT64,
     sale_amount NUMERIC
   );

   INSERT INTO \`${PROJECT_ID}.${BQ_DATASET_ID}.fact_sales\` VALUES
     ('T1001', '2026-03-01', 'P101', 'North America', 3, 360.00),
     ('T1002', '2026-03-01', 'P102', 'North America', 5, 125.00),
     ('T1003', '2026-03-02', 'P103', 'Europe', 2, 190.00),
     ('T1004', '2026-03-02', 'P101', 'Europe', 2, 240.00),
     ('T1005', '2026-03-03', 'P104', 'Asia Pacific', 10, 180.00),
     ('T1006', '2026-03-03', 'P103', 'North America', 4, 380.00);
   EOF
   ```
3. Create a view in BigQuery that joins `fact_sales` with the
   `dim_products` table, and query the view to calculate revenue and gross
   margin by product:

   ```bash
   bq query \
       --project_id="${PROJECT_ID}" \
       --location="${REGION}" \
       --use_legacy_sql=false << EOF
   CREATE OR REPLACE VIEW \`${PROJECT_ID}.${BQ_DATASET_ID}.v_cross_cloud_sales_margins\` AS
   SELECT
     s.transaction_id,
     s.sale_date,
     s.store_region,
     p.product_id,
     p.product_name,
     p.category,
     p.brand,
     s.quantity,
     s.sale_amount,
     ROUND(s.quantity * CAST(p.unit_cost AS NUMERIC), 2) AS total_cost,
     ROUND(s.sale_amount - (s.quantity * CAST(p.unit_cost AS NUMERIC)), 2) AS gross_margin
   FROM \`${PROJECT_ID}.${BQ_DATASET_ID}.fact_sales\` AS s
   INNER JOIN \`${PROJECT_ID}.${FEDERATED_CATALOG_ID}.${UNITY_NAMESPACE}.dim_products\` AS p
     ON s.product_id = p.product_id;

   SELECT
     product_name,
     category,
     SUM(quantity) AS units_sold,
     ROUND(SUM(sale_amount), 2) AS total_revenue,
     ROUND(SUM(gross_margin), 2) AS total_gross_margin
   FROM \`${PROJECT_ID}.${BQ_DATASET_ID}.v_cross_cloud_sales_margins\`
   GROUP BY product_name, category
   ORDER BY total_gross_margin DESC;
   EOF
   ```

   The output is similar to the following:

       +---+---+---+---+---+
       |      product_name      |  category   | units_sold | total_revenue | total_gross_margin |
       +---+---+---+---+---+
       | Ultralight Daypack     | Gear        |          6 |           570 |                318 |
       | Trail Running Shoes    | Footwear    |          5 |           600 |                310 |
       | Merino Wool Socks      | Apparel     |         10 |           180 |               97.5 |
       | Insulated Water Bottle | Accessories |          5 |           125 |               62.5 |
       +---+---+---+---+---+

   Because you enabled cross-cloud caching, which has no additional charge,
   Lakehouse caches retrieved file blocks in your catalog's
   region. Repeated queries can read from the cache. Caching helps reduce
   egress costs, and actual savings depend on your query patterns. To view
   cache metrics, see [Monitor cache usage and egress cost
   savings](https://docs.cloud.google.com/lakehouse/docs/query-remote-data#caching-stats).

## Clean up

To avoid incurring charges to your Google Cloud and Databricks accounts
for the resources used in this tutorial, delete the Google Cloud resources
(by deleting the project or by deleting the individual resources) and then
delete the Databricks resources.

### Delete the Google Cloud project

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

1. In the Google Cloud console, go to the **Manage resources** page.

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
2. In the project list, select the project that you want to delete, and then click **Delete**.
3. In the dialog, type the project ID, and then click **Shut down** to delete the project.

> [!NOTE]
> **Note:** Deleting your Google Cloud project doesn't remove any resources in Databricks. Complete the steps in [Delete Databricks resources](https://docs.cloud.google.com/lakehouse/docs/query-databricks-unity-catalog-tutorial.md.txt#delete-databricks-resources) to avoid ongoing Databricks charges.

### Delete individual Google Cloud resources

To keep your Google Cloud project, run the following commands in
Cloud Shell to delete the BigQuery dataset and the
federated catalog:

```bash
bq rm -r -f -d "${PROJECT_ID}:${BQ_DATASET_ID}"

gcloud biglake iceberg catalogs delete ${FEDERATED_CATALOG_ID} \
    --project="${PROJECT_ID}" \
    --quiet
```

### Delete Databricks resources

Delete the resources that you created in Databricks:

1. In the Databricks **SQL Editor**, drop the sample table and schema. If you
   created the catalog specifically for this tutorial, also drop the catalog:

   ```sql
   DROP TABLE IF EXISTS UNITY_CATALOG_NAME.retail_db.dim_products;
   DROP SCHEMA IF EXISTS UNITY_CATALOG_NAME.retail_db;
   -- Run the following statement only if you created this catalog for the tutorial:
   DROP CATALOG IF EXISTS UNITY_CATALOG_NAME CASCADE;
   ```

   Replace `UNITY_CATALOG_NAME` with the name of your target
   catalog in Databricks Unity Catalog.
2. In your Databricks account console, delete the service principal federation
   policy and the Databricks service principal that you created for this
   tutorial. For instructions, see the Databricks documentation for
   federation policies
   ([AWS](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-federation-policy#workload-identity-federation),
   [Azure](https://learn.microsoft.com/azure/databricks/dev-tools/auth/oauth-federation-policy),
   [Google Cloud](https://docs.databricks.com/gcp/en/dev-tools/auth/oauth-federation-policy))
   and service principals
   ([AWS](https://docs.databricks.com/aws/en/admin/users-groups/manage-service-principals),
   [Azure](https://learn.microsoft.com/azure/databricks/admin/users-groups/service-principals),
   [Google Cloud](https://docs.databricks.com/gcp/en/admin/users-groups/service-principals)).

3. If you created a Databricks SQL warehouse or compute cluster for this
   tutorial, stop or delete it. For instructions on managing SQL warehouses,
   see the Databricks documentation for
   [AWS](https://docs.databricks.com/aws/en/compute/sql-warehouse),
   [Azure](https://learn.microsoft.com/azure/databricks/compute/sql-warehouse),
   or
   [Google Cloud](https://docs.databricks.com/gcp/en/compute/sql-warehouse).

## What's next

- Configure private network routing with Cross-Cloud Interconnect in [Set up cross-cloud connection for Databricks Unity
  Catalog](https://docs.cloud.google.com/lakehouse/docs/set-up-cross-cloud-connection-databricks).
- Query your federated catalog by using Managed Service for Apache Spark or open source Apache Spark in [Query remote
  data](https://docs.cloud.google.com/lakehouse/docs/query-remote-data#query-spark).
- Analyze federated tables in natural language in [Query
  Lakehouse tables with natural
  language](https://docs.cloud.google.com/lakehouse/docs/conversational-analytics).
- Diagnose connectivity and permission issues in [Troubleshoot cross-cloud
  data access for Databricks Unity
  Catalog](https://docs.cloud.google.com/lakehouse/docs/troubleshoot-cross-cloud-data-access#databricks-issues).