> 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/reference/data-source-reference-for-soda-core/databricks.md).

# Databricks SQL

> For information about how to connect to Databricks Spark Dataframes, see: [Spark Dataframe](/reference/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 three 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></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`.            |

{% 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.                     |

***

### Test the connection

Test the data source connection:

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

***

{% if visitor.claims.plan === 'datasetStandard' %}
{% hint style="success" %}
You are **logged in to Soda** and seeing the **Dataset Standard license** documentation. Learn more about [Documentation access & licensing](/reference/documentation-access-and-licensing.md).
{% endhint %}
{% endif %}

{% if visitor.claims.plan === 'enterprise' %}
{% hint style="success" %}
You are **logged in to Soda** and seeing the **Team license** documentation. Learn more about [Documentation access & licensing](/reference/documentation-access-and-licensing.md).
{% endhint %}
{% endif %}

{% if visitor.claims.plan === 'enterpriseUserBased' %}
{% hint style="success" %}
You are **logged in to Soda** and seeing the **Enterprise license** documentation. Learn more about [Documentation access & licensing](/reference/documentation-access-and-licensing.md).
{% endhint %}
{% endif %}

{% if !(visitor.claims.plan === 'enterprise' || visitor.claims.plan === 'enterpriseUserBased' || visitor.claims.plan === 'datasetStandard') %}
{% hint style="info" %}
You are **not logged in to Soda** and are viewing the default public documentation. Learn more about [Documentation access & licensing](/reference/documentation-access-and-licensing.md).

If you do have a Soda license, make sure to **log in to Soda Cloud in this same browser**.
{% endhint %}
{% endif %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
