> For the complete documentation index, see [llms.txt](https://docs.soda.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.soda.io/soda-documentation/developer-tools/data-source-reference-for-soda-core/databricks.md). Agents can also search and read this documentation through its [MCP server](https://docs.soda.io/~gitbook/mcp).

# Databricks SQL

Access configuration details to connect Soda to a Databricks SQL data source.

> For information about how to connect to Databricks Spark Dataframes, see: [Spark Dataframe](https://docs.soda.io/soda-documentation/developer-tools/data-source-reference-for-soda-core/spark-dataframe.md#example-contract-spark-databricks)

## Connection configuration reference

Install the following package:

```bash
pip install soda-databricks
```

### Data source YAML

#### Core connection

**Create the config file:**

```shellscript
soda data-source create -f ds_config.yml
```

Databricks supports four authentication methods. Set `auth_type` to choose one. If you omit `auth_type`, Soda uses personal access token authentication.

<table><thead><tr><th width="304.99993896484375">Authentication method</th><th>Soda Cloud support</th><th>Soda Core support</th></tr></thead><tbody><tr><td><a href="#id-1.-personal-access-token">Personal access token</a></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td><a href="#id-2.-databricks-oauth-machine-to-machine">Databricks OAuth (machine-to-machine)</a></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td><a href="#id-3.-azure-service-principal">Azure service principal</a></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td><a href="#azure-workload-identity">Azure workload identity (managed identity)</a></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr></tbody></table>

Every method shares these connection parameters:

| Parameter               | Required | Default                 | Description                                                                                                                          |
| ----------------------- | -------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `type`                  | Yes      | —                       | Must be `databricks`.                                                                                                                |
| `host`                  | Yes      | —                       | Databricks workspace hostname, for example `abc.cloud.databricks.com`. A leading `https://` or `http://` is removed.                 |
| `http_path`             | Yes      | —                       | HTTP path for the SQL warehouse or cluster.                                                                                          |
| `catalog`               | No       | —                       | Default catalog to use.                                                                                                              |
| `session_configuration` | No       | —                       | Optional session configuration dictionary.                                                                                           |
| `auth_type`             | No       | `personal-access-token` | Authentication method. One of `personal-access-token`, `databricks-oauth-m2m`, `azure-service-principal`, `azure-workload-identity`. |

{% hint style="info" %}
**Hive Metastore is supported**. When the `catalog` is set to `hive_metastore`, Soda will use Hive-compatible queries.
{% endhint %}

#### Personal access token

Supported in Soda Cloud and Soda Core.

{% code title="ds\_config.yml" %}

```yaml
type: databricks
name: my_databricks
connection:
  host: ${env.DATABRICKS_HOST}
  http_path: ${env.DATABRICKS_SQL_HTTP_PATH}
  catalog: ${env.DATABRICKS_CATALOG}

  # auth_type: personal-access-token   # optional; the default when omitted
  access_token: ${env.DATABRICKS_SQL_ACCESS_TOKEN}

  ## optional
  # session_configuration: <session configuration dict>
```

{% endcode %}

| Parameter      | Required | Default                 | Description                              |
| -------------- | -------- | ----------------------- | ---------------------------------------- |
| `auth_type`    | No       | `personal-access-token` | Omit, or set to `personal-access-token`. |
| `access_token` | Yes      | —                       | Databricks personal access token.        |

***

#### Databricks OAuth (machine-to-machine)

Supported in Soda Cloud and Soda Core.

Authenticates with a Databricks-managed OAuth service principal using the client-credentials flow. Create the service principal and generate an OAuth secret in Databricks (see Databricks' documentation on [OAuth machine-to-machine (M2M) authentication](https://docs.databricks.com/en/dev-tools/auth/oauth-m2m.html)). Soda derives the token endpoint from `host`, so no token URL is required.

{% code title="ds\_config.yml" %}

```yaml
type: databricks
name: my_databricks
connection:
  host: ${env.DATABRICKS_HOST}
  http_path: ${env.DATABRICKS_SQL_HTTP_PATH}
  catalog: ${env.DATABRICKS_CATALOG}

  auth_type: databricks-oauth-m2m
  client_id: ${env.DATABRICKS_CLIENT_ID}
  client_secret: ${env.DATABRICKS_CLIENT_SECRET}
```

{% endcode %}

| Parameter       | Required | Default | Description                                       |
| --------------- | -------- | ------- | ------------------------------------------------- |
| `auth_type`     | Yes      | —       | Must be `databricks-oauth-m2m`.                   |
| `client_id`     | Yes      | —       | Databricks OAuth service-principal client ID.     |
| `client_secret` | Yes      | —       | Databricks OAuth service-principal client secret. |

***

#### Azure service principal

Supported in Soda Cloud and Soda Core.

Authenticates Azure Databricks with a Microsoft Entra ID (Azure AD) service principal. Register the application in Entra ID and note its client ID, client secret, and directory (tenant) ID (see Microsoft's documentation on [creating a Microsoft Entra ID application and service principal](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal)). Soda requests the token from `login.microsoftonline.com`, so the tenant ID is required.

{% code title="ds\_config.yml" %}

```yaml
type: databricks
name: my_databricks
connection:
  host: ${env.DATABRICKS_HOST}
  http_path: ${env.DATABRICKS_SQL_HTTP_PATH}
  catalog: ${env.DATABRICKS_CATALOG}

  auth_type: azure-service-principal
  azure_client_id: ${env.DATABRICKS_AZURE_CLIENT_ID}
  azure_client_secret: ${env.DATABRICKS_AZURE_CLIENT_SECRET}
  azure_tenant_id: ${env.DATABRICKS_AZURE_TENANT_ID}
```

{% endcode %}

| Parameter             | Required | Default | Description                                                  |
| --------------------- | -------- | ------- | ------------------------------------------------------------ |
| `auth_type`           | Yes      | —       | Must be `azure-service-principal`.                           |
| `azure_client_id`     | Yes      | —       | Entra ID (Azure AD) service-principal application/client ID. |
| `azure_client_secret` | Yes      | —       | Entra ID (Azure AD) service-principal client secret.         |
| `azure_tenant_id`     | Yes      | —       | Entra ID (Azure AD) directory/tenant ID.                     |

***

#### Azure workload identity <a href="#azure-workload-identity" id="azure-workload-identity"></a>

Supported in Soda Cloud and Soda Core.

Authenticates to Azure Databricks as a user-assigned managed identity through [Microsoft Entra Workload ID](https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview). Soda exchanges the Kubernetes service account token of its pod for a Microsoft Entra access token for Azure Databricks, so no client secret or access token is stored in Soda Cloud or in the cluster.

{% code title="ds\_config.yml" %}

```yaml
type: databricks
name: my_databricks
connection:
  host: ${env.DATABRICKS_HOST}
  http_path: ${env.DATABRICKS_SQL_HTTP_PATH}
  catalog: ${env.DATABRICKS_CATALOG}

  auth_type: azure-workload-identity
  # optional: defaults to AZURE_CLIENT_ID from the pod environment
  client_id: <managed-identity-client-id>
  # optional: defaults to AZURE_TENANT_ID from the pod environment
  tenant_id: <managed-identity-tenant-id>
```

{% endcode %}

| Parameter   | Required | Default                      | Description                                                                                                                                                                                 |
| ----------- | -------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `auth_type` | Yes      | —                            | Must be `azure-workload-identity`.                                                                                                                                                          |
| `client_id` | No       | `AZURE_CLIENT_ID` of the pod | Client ID of the user-assigned managed identity. Set it to connect as a different managed identity from the one in the service account annotation.                                          |
| `tenant_id` | No       | `AZURE_TENANT_ID` of the pod | Microsoft Entra tenant ID of the managed identity, as a GUID or a domain such as `contoso.onmicrosoft.com`. Set it only when the managed identity is in a different tenant from the runner. |

* Requires Soda Core `4.32.0` or later. On a Soda Runner, it requires version `2.0.24` or later of the Soda Runner Helm chart.
* Soda reads `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, and `AZURE_FEDERATED_TOKEN_FILE` from the environment. On AKS, the Azure workload identity webhook sets them. To set this up for a Soda Runner, follow steps 1 to 4 of [Using workload identities](broken://pages/pmlXAjXhh0S0pwrxzvO1#using-workload-identities).
* An empty `client_id` or `tenant_id`, such as an unset `${env.X}` variable, is an error. Leave the parameter out to use the value from the pod environment.
* Leave out `access_token`, `client_secret`, `azure_client_id`, `azure_client_secret`, and `azure_tenant_id`.
* Soda requests tokens for Azure Databricks only; no parameter changes the token scope. Soda renews the token before it expires, so long contract runs keep working.

In the connection form in Soda Cloud, choose **Workload Identity Federation (Managed Identity)** as the authentication method. The optional **client\_id** and **tenant\_id** fields map to the parameters above. Switching an existing connection to this method removes its stored secrets.

**Add the managed identity to Databricks**

Databricks accepts the token only from a service principal that is a member of the workspace. A Databricks account admin and a workspace admin do the following:

1. Look up the client ID of the managed identity.

   ```bash
   az identity show \
     --name <managed-identity-name> \
     --resource-group <resource-group> \
     --query clientId \
     --output tsv
   ```
2. In the Databricks account console, add a service principal with **Management: Microsoft Entra ID managed**, and enter the client ID from step 1 as the **Microsoft Entra application ID**. Use the client ID, not the object (principal) ID of the managed identity. See Databricks' documentation on [adding service principals to your account](https://learn.microsoft.com/en-us/azure/databricks/admin/users-groups/service-principals#add-service-principals-to-your-account).
3. Assign the service principal to the workspace in `host`, with the **User** permission.

**Grant the managed identity access**

Grant the service principal the same access to the SQL warehouse and to your data as any other identity that Soda connects with. Workload identity changes only how Soda authenticates, not the permissions it needs. In Unity Catalog, refer to the service principal by the client ID of the managed identity.

> If this workspace is also the target of a Diagnostics Warehouse, the service principal also needs write access. Refer to [Diagnostics Warehouse required permissions](broken://pages/dWoYeagXP1e77Kf8TS5K#diagnostics-warehouse-required-permissions).

**Several business units**

When one Soda Runner checks the Databricks workspaces of several business units, each business unit adds a managed identity to its own workspace and grants it access to its own data. It revokes that access by removing the service principal from the workspace.

The business units can all add the same managed identity, the one in the service account annotation, and their data sources leave out `client_id`. Or each business unit adds its own managed identity, with a federated credential for the runner, and each data source names that managed identity with `client_id`.

An Azure Databricks account belongs to one Microsoft Entra tenant. When a business unit's Databricks account is in a different tenant from the runner, the business unit creates the managed identity in its own tenant, and the data source sets both `client_id` and `tenant_id`. Follow [Managed identities in other Entra tenants](broken://pages/pmlXAjXhh0S0pwrxzvO1#managed-identities-in-other-entra-tenants). For its step 3, the business unit adds the managed identity to its own Databricks account and workspace as described above.

```yaml
type: databricks
name: business_unit_a_databricks
connection:
  host: ${env.DATABRICKS_HOST}
  http_path: ${env.DATABRICKS_SQL_HTTP_PATH}
  catalog: ${env.DATABRICKS_CATALOG}
  auth_type: azure-workload-identity
  client_id: <business-unit-managed-identity-client-id>
  tenant_id: <business-unit-tenant-id>
```

**Troubleshoot Azure workload identity**

**Problem:** The connection fails with `Workload identity federation is not set up for this pod`, followed by the Azure environment variables that are not set.

**Solution:** The contract launcher pod has no Azure workload identity environment. See [Troubleshoot workload identity](broken://pages/pmlXAjXhh0S0pwrxzvO1#using-workload-identities) on the runner page.

**Problem:** The connection fails with `Entra ID rejected the workload identity token exchange for client ID '...' in tenant '...'`, followed by an `AADSTS` error.

**Solution:** Microsoft Entra ID refused to issue a token, so the request never reached Databricks. Check the federated credential as described in [Troubleshoot workload identity](broken://pages/pmlXAjXhh0S0pwrxzvO1#using-workload-identities). For `AADSTS700016`, see [Troubleshoot managed identities in other tenants](broken://pages/pmlXAjXhh0S0pwrxzvO1#managed-identities-in-other-entra-tenants).

**Problem:** The connection fails with `Could not get an Entra access token through workload identity federation for client ID '...'`.

**Solution:** Soda could not reach Microsoft Entra ID, or could not read the service account token file. Check that the file in `AZURE_FEDERATED_TOKEN_FILE` is mounted in the contract launcher pod, and that the network policy or proxy of the runner allows `login.microsoftonline.com`, or the host in `AZURE_AUTHORITY_HOST` if it is set.

**Problem:** The connection fails with `An Entra access token was acquired through workload identity federation, but Databricks workspace '...' rejected it with HTTP 401` or `HTTP 403`.

**Solution:** Entra issued the token, but Databricks refused it. Check that:

* the managed identity is a service principal in the Databricks account, added with its client ID, and is assigned to the workspace in `host`.
* the service principal has access to the SQL warehouse in `http_path` and to the data, as described in [Grant the managed identity access](#azure-workload-identity).

***

### Test the connection

Test the data source connection:

```bash
soda data-source test -ds ds_config.yml
```

{% hint style="warning" %}

#### **Row-level security**

If your data source uses row-level security policies (e.g. Row Access Policies in Snowflake, Row-Level Security in PostgreSQL or SQL Server, Row Filters in Databricks Unity Catalog, or equivalent mechanisms in other data sources), **ensure that the Soda connection** user or role **has been granted the appropriate policy exemptions or access**.

Row-level security policies do not cause connection errors or scan failures, but **they silently filter the rows visible to Soda**. This can produce unexpected results. For example, `dataset_rows_tested: 0` even when the dataset clearly contains rows.
{% endhint %}

<br>

***

{% hint style="info" %}
You are **not logged in to Soda** and are viewing the default public documentation.

Learn more about [Licensing & documentation access](https://docs.soda.io/soda-documentation/govern/security-licensing-and-compliance/documentation-access-and-licensing.md) or <a href="https://docs.soda.io/~gitbook/auth/login" class="button primary small">Log in to Soda Cloud</a>.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.soda.io/soda-documentation/developer-tools/data-source-reference-for-soda-core/databricks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
