Databricks SQL
BInbox runs queries on a Databricks SQL warehouse through the Statement Execution API. It signs in as a service principal with an OAuth secret (machine to machine), and gets its token at the workspace’s own token endpoint.
What you will paste into BInbox
Section titled “What you will paste into BInbox”On New connection, choose Databricks SQL.
| Field | What to enter |
|---|---|
| Workspace host | The workspace’s host name, such as dbc-1234abcd-5678.cloud.databricks.com. It must end in cloud.databricks.com, azuredatabricks.net or gcp.databricks.com. |
| SQL warehouse ID | The id of the SQL warehouse that runs the queries. Open the warehouse, then Connection details. It is 8 to 64 letters and digits. |
| Catalog | The Unity Catalog catalog to read. |
| Schema | Optional. The schema a table name without one is read from. |
| How BInbox signs in | A service principal’s client id and secret. This is the only choice. |
| Service principal’s client ID | The service principal’s application (client) id. |
| OAuth secret | The secret made for that service principal. |
Make the service principal
Section titled “Make the service principal”In the workspace
Section titled “In the workspace”- Open the account console, User management, Service principals, then Add service principal. Name it
binbox-reader. Copy its Application ID, which is the client id. - Open the workspace, Settings, Identity and access, Service principals, and add
binbox-readerto the workspace. Give it the entitlement Databricks SQL access and no other. - Open the service principal, Secrets, Generate secret. Copy the secret now, because Databricks shows it once.
- Open SQL Warehouses, the warehouse, Permissions, and give
binbox-readerCan use.
With the command line
Section titled “With the command line”databricks account service-principals create --display-name binbox-readerdatabricks account service-principal-secrets create <service principal id>The first command prints the application id, and the second prints the secret once. Add the service principal to the workspace and give it Can use on the warehouse in the console as above.
Grant the data
Section titled “Grant the data”Run these statements in a SQL editor as a catalog owner. Replace the names in angle brackets, and use the application id as the principal’s name, in backticks.
GRANT USE CATALOG ON CATALOG <catalog> TO `<application id>`;GRANT USE SCHEMA ON CATALOG <catalog> TO `<application id>`;GRANT SELECT ON CATALOG <catalog> TO `<application id>`;To read one schema only, grant on SCHEMA <catalog>.<schema> instead, and fill in Schema in BInbox.
Least permissions
Section titled “Least permissions”| Grant | Why BInbox needs it |
|---|---|
| Databricks SQL access entitlement | To use a SQL warehouse. |
| Can use on the SQL warehouse | To run queries on it. |
USE CATALOG and USE SCHEMA |
To list the catalog’s schemas. |
SELECT |
To read tables and views. |
Do not grant MODIFY, CREATE or ALL PRIVILEGES.
Check: the test-connection report
Section titled “Check: the test-connection report”Choose Test connection in BInbox. The first four permissions must be Granted, and the last is optional:
| Permission | Granted when |
|---|---|
| Sign in as the service principal | The workspace’s token endpoint accepts the client id and secret. |
| Run a query on the SQL warehouse | A query of the SQL version runs on the warehouse. |
| List the schemas in the catalog | The service principal may use at least one schema besides information_schema. |
| Read at least one table | It may see at least one table besides information_schema’s. |
| Refuse a write, so SQL an author writes can run (optional) | Databricks refuses a delete of no rows from the first table the service principal can see, DELETE FROM <table> WHERE 1 = 0, for want of a permission. No read-only session exists, so the principal’s grants are the control, and the test shows that one table refused. Delta tables have no rollback: if the principal may write, the delete can leave an empty entry in the table’s history, and the report says the principal can write. Without this, authors still pick tables, but cannot write a dataset’s SQL. |
If Run a query is refused, the warehouse id is wrong, the warehouse is not shared with the service principal, or the workspace’s IP access list blocks BInbox. The report quotes Databricks’ own error.
Add it in BInbox
Section titled “Add it in BInbox”An owner or admin opens the Data tab at app.binbox.ai, chooses Connect, then New connection, fills in the fields above, and chooses Test and save. Connections describes the screen.
Then an author sets up a dataset from one of the connection’s tables or views, as Pick a table describes.