Databricks Connector

A StrataBI Platform Module

Powered by Shaleio

module id databricks_connector · requires StrataBI · one of the data-source connectors

Read-only SQL against a Databricks SQL warehouse (Unity Catalog) for StrataBI tiles. A tile sends one query and its parameters; one Lambda function in your own AWS account, <name_prefix>-databricks_connector-query, runs it through Databricks' SQL Statement Execution API as a service principal (OAuth machine-to-machine), and writes the rows to your own S3 as the tile's result. Values are sent as named parameters, each query has a time budget and is cancelled in Databricks at its deadline, results are typed, and the service principal's secret stays in your Secrets Manager. The connector is available. Live on Databricks Free Edition (2026-12-03): sign-in with the read-only SQL scope, table listing, and queries read through result links. Cancel, timeouts and large results are tested against a local stand-in of the Statement Execution API; Tested lists what has run.

Results come from the workspace's cloud storage, not from the API. Every query asks Databricks for external links: the rows arrive as Arrow files that the function downloads, in parallel, from presigned links on the workspace's own cloud storage. This is the connector's standard path, and it has no native_reader setting. It works on Databricks Free Edition too, which redirects result downloads to a Databricks-hosted address that the connector follows. The function must reach that storage over HTTPS as well as the workspace (The network). The fallback, results = inline, needs only the workspace, but Databricks then returns at most 25 MiB of rows per query.

text
tile (SQL + inputs) → query Lambda → your Databricks SQL warehouse (service principal, read grants only)
                           │  ↑
                           │  └─ Arrow result files, from the workspace's own cloud storage
                           └→ typed Parquet in your S3 → the tile

This page covers dashboard tiles. Using the connector from StrataLake depends on StrataLake changes that are still in development.

Before installing

1. A SQL warehouse with auto-stop

Use a small warehouse, serverless if the workspace has it (it starts in seconds): size 2X-Small, auto-stop after 5 to 10 minutes (serverless allows 1 minute), and the warehouse's own STATEMENT_TIMEOUT (a SQL configuration parameter, in seconds) set to 900 as a backstop. Copy its HTTP path from Connection details (/sql/1.0/warehouses/<id>).

2. A service principal with read grants only

Create a service principal (in the account console or the workspace settings). Give it the "Databricks SQL access" entitlement and CAN USE on the warehouse, and generate an OAuth secret for it: its client id is the principal's application id. Then grant it read access in Unity Catalog, with your own catalog and schemas:

sql
GRANT USE CATALOG ON CATALOG analytics TO `<application-id>`;
GRANT USE SCHEMA ON SCHEMA analytics.sales TO `<application-id>`;
GRANT SELECT ON SCHEMA analytics.sales TO `<application-id>`;

Give it nothing else: no MODIFY, ALL PRIVILEGES, CREATE, MANAGE or ownership, and do not add it to the workspace admins group. Databricks has no read-only session, so these grants are what make the connection read-only. The connector also refuses writes itself (below), but the grants are the control.

3. The sign-in: a secret, or a StrataAPI Manager credential

Each connection signs in with exactly one of the two, never both.

An AWS Secrets Manager secret (secret_arn) with the service principal's OAuth credentials:

json
{"client_id": "<application id>", "client_secret": "<OAuth secret>"}

For each query the connector exchanges the client id and secret for a one-hour token at the workspace's /oidc/v1/token, and keeps neither past that query. Only this connector's function can read the secret. A secret encrypted with a customer-managed KMS key needs secret_kms_key_arn.

A StrataAPI Manager credential (strataapi_credential). In StrataAPI Manager, an administrator adds a credential with provider databricks, scheme basic, as a service account: its username is the client id and its password is the OAuth secret. Bind it to databricks_connector.

The OAuth scope (oauth_scope, all-apis by default) is what the token request asks for. Databricks issues a token only for a scope it has assigned the service principal. A principal that Databricks gave only read-only SQL (for example on Databricks Free Edition) needs sql:read:restricted-query. Under that scope the connector cannot open a session, so statements run with the warehouse alone, under the warehouse's own statement timeout and time zone: set the warehouse's STATEMENT_TIMEOUT to 900 s. The connector never switches scopes by itself.

4. The network: HTTPS to the workspace and its storage

Where the function reaches Databricks fromWhat to set
The internet (the default)Nothing: the function runs outside a VPC and reaches the workspace and its storage over the internet.
A workspace IP access listsubnet_ids and security_group_ids: private subnets behind a NAT gateway with a fixed address.
AWS PrivateLink to the workspacesubnet_ids and security_group_ids: the subnets that reach the endpoint.

The function connects out on port 443 only:

HostWhat for
The workspace host (dbc-....cloud.databricks.com, adb-....azuredatabricks.net or ....gcp.databricks.com)The OAuth token, sessions, statements, result links, cancel
The workspace's cloud storage: on AWS its S3 bucket; on Azure <account>.blob.core.windows.net or .dfs.core.windows.net; on Google Cloud storage.googleapis.comResult files, through presigned links (not with results = inline)
s3.<region>.amazonaws.com, secretsmanager.<region>.amazonaws.com, lambda.<region>.amazonaws.comResults, the secret, StrataBI's status writer
dynamodb.<region>.amazonaws.comOnly with a StrataAPI Manager credential

The install's egress output lists these, except the storage host: it belongs to the workspace, and the install cannot name it. Inside a VPC, the subnets need a route to that storage: on AWS a NAT gateway, or an S3 gateway endpoint when the workspace's bucket is in the function's region (its endpoint policy must allow that bucket, and the bucket's policy must not refuse requests from the VPC); for Azure or Google Cloud storage, a NAT gateway. If your network allows outbound traffic only to listed hosts, include the storage host. On Free Edition, result downloads are redirected to a storage host under databricks.com: allow that too. Its full name is not given here, because the connector logs only the end of it. Without the route, the first query fails as unavailable.

A redirected download is followed only over HTTPS, for at most three hops, and only into the workspace's cloud storage or a Databricks domain of that cloud, never with the workspace's sign-in header or cookies. A redirect anywhere else, or too many, fails as unavailable (tested against the local stand-in only). results = inline avoids the storage altogether, up to 25 MiB a result. See also Databricks and BigQuery: where large results come from.

Every call is HTTPS, and only https:// result links are followed. Before it sends the client secret, the connector checks that the host is a Databricks workspace name.

Install

Install StrataBI first: the function uses its AWS SDK for pandas layer to write Parquet.

powershell
stratactl install databricks_connector

Answer the settings with stratactl init module databricks_connector, which saves them in strata.yaml; stratactl install then stores them. Answer the sign-in (secret_arn or strataapi_credential), host and http_path: all three start blank, and an install with no connection stops at its check: "Install at least one connection".

SettingDefault
secret_arn or strataapi_credentialOne of the twoThe secret's ARN, or a StrataAPI Manager credential's name.
hostRequiredThe workspace host name, as in https://<host>.
http_pathRequiredThe SQL warehouse's HTTP path. The service principal needs CAN USE on the warehouse.
catalogThe workspace's defaultThe Unity Catalog catalog the queries run in. Tables are named schema.table in it.
default_schemaNoneThe schema an unqualified table name resolves to. Without one, name tables as schema.table.
resultsexternal_linksArrow files downloaded in parallel from the workspace's cloud storage, up to the API's 100 GiB. Or inline: JSON rows, cut by the API at 25 MiB, for a function that cannot reach that storage.
oauth_scopeall-apisThe scope the token asks for. sql:read:restricted-query for a principal Databricks gave only read-only SQL.
subnet_ids, security_group_idsNoneOnly for AWS PrivateLink to the workspace, or an IP access list that admits a NAT gateway's fixed address. The security group allows outbound HTTPS on 443.
sync_timeout_seconds25A sync query's budget when the call carries none of its own. A cold warehouse can take longer than 25 s to start: keep tiles async, or the warehouse warm.
max_query_seconds900The async timeout: the longest any query runs. You may lower it; see Timing.
max_rows, max_result_mb0, 0 (no limit)Per result. A positive value cuts the result there, and the result says so.
memory_mb10,240The function's memory in MB; the default is Lambda's maximum. A new AWS account may allow only 3,008 MB until AWS raises it: ask AWS Support, or set 3008.
result_layoutautoHow a large result is written: single, prefix (parts plus a manifest), or auto. A tile's exec.result_layout overrides it.
allowed_schemasAll the principal can read
allowed_catalogsNoneOther catalogs a query may name as catalog.schema.table. Without any, queries stay in the connection's catalog.
dashboard_tiles, stratalake_accessOn, on
secret_kms_key_arnNoneThe customer-managed KMS key that encrypts the secret.

To change a setting later, edit strata.yaml and run stratactl update databricks_connector --reconfigure. Tiles use the install's default connection.

From a tile

json
{"id": "revenue_by_region", "title": "Revenue by region",
 "exec": {"type": "lambda", "module_id": "databricks_connector", "lambda_index": 0},
 "query": {"sql": ["SELECT region, sum(total) AS revenue FROM sales.orders",
                   "WHERE ordered_at >= :since GROUP BY region ORDER BY revenue DESC"],
           "params": {"since": "since_date"}},
 "block": {"type": "table"}}

What it does in Databricks

Every query goes through these, in order:

  1. One read-only statement. The SQL is parsed as Databricks SQL. Only a SELECT, or a set operation of them, with or without CTEs, may run: nothing that writes, defines, loads, calls out or runs a command, no table functions, no schema-qualified function calls, and no row locks. This check explains a refusal early; it is not the control.
  2. Allowed schemas and catalogs, from allowed_schemas and allowed_catalogs.
  3. Values sent as named parameters.
  4. The service principal's read grants, which are what make the connection read-only. Databricks has no read-only session.
  5. Limits: the time budget, and max_rows and max_result_mb.

For each query the connector:

  1. gets a token from the workspace's /oidc/v1/token;
  2. opens a session on the warehouse with the catalog and schema, a STATEMENT_TIMEOUT of the time left plus 1 s, TIMEZONE = UTC and ANSI_MODE = true (where the workspace refuses sessions, the warehouse's own timeout applies);
  3. submits the statement with external links and Arrow results, and the values as named parameters. A tile waits in that request for up to 50 s, never past its deadline, so a quick query answers in one round trip;
  4. polls the statement (every 50 ms, doubling to 1 s) until it ends, downloads the result, and closes the session.

Every call uses version 2.0 of the API (/api/2.0/sql/...). The warehouse's query history shows each statement under the service principal.

Each query writes one audit line to the function's log: who asked (and whether StrataBI verified it), a SHA-256 fingerprint of the SQL, the tables read, how many values, the connection, the outcome and Databricks' error code, rows, bytes and times. Never the SQL text, the values, the rows or a secret.

Why the Statement Execution API. Databricks' Python client, databricks-sql-connector 4.10.0, is 14.3 MiB, or 32.7 MiB with its kernel extra (measured for arm64 and Python 3.13, without pandas, numpy and pyarrow). It fits a connector's package budget, but its default backend is the client's legacy path, it loads pandas when it starts, and it cannot be tested faithfully without a workspace. The REST API is documented request by request. This connector speaks it directly, and its package is 3.4 MiB.

Results

Every statement asks for external links with Arrow results. Databricks answers with a list of chunks; each chunk is an Arrow stream behind a presigned link to the workspace's own cloud storage. The connector reads up to 8 chunks at a time on parallel streams, decoding each as it arrives, with no Python object per value.

The result is typed Parquet in your deployment's bucket. With result_layout = auto, a result read on parallel streams is written as Parquet parts plus a manifest, and a result read as one stream as one file. A tile that asks for CSV gets one CSV file.

DatabricksIn the result
The integer types64-bit integer
FLOAT64-bit float
DECIMALDecimal, with the column's declared precision and scale
TIMESTAMPTimestamp in UTC
TIMESTAMP_NTZTimestamp, without a time zone
ARRAY, MAP, STRUCTJSON text
Every other typeIts Arrow type as Databricks sends it, normalised to the result's types

A value that cannot be converted to its column's type is kept as text. A result cut at max_rows or max_result_mb, or by the API's own limit, is marked as cut, never silently short, and the tile says so.

results = inline keeps the rows in the API's answer as JSON, for a function that cannot reach the workspace's storage. The API then cuts a result at 25 MiB, and the connector marks it as cut.

Timing

A tenth of the budget (0.5–3 s) is kept back to cancel, write and report. At the deadline the connector cancels the statement in Databricks and closes the downloads in flight, so a blocked read ends at once. The session's STATEMENT_TIMEOUT (the time left plus 1 s) is a backstop on the server, and so is the warehouse's own STATEMENT_TIMEOUT. The tile then says, for example:

The query did not finish within its 25 s budget and was cancelled. Narrow it (filters, fewer columns or rows) or run it as a background tile.

Lambda now allows a function up to 1,800 s, but the install accepts at most 900 s for now: the OpenTofu AWS provider still refuses a longer Lambda timeout. Past 15 minutes, a workload needs S3 caching or a module's own async logic (see Data-source connectors).

One attempt per query

Lambda never retries a connector query: automatic retries are off for the function, and that is not a setting. A query runs once, and a late status from an old attempt cannot overwrite a newer run's.

Errors

The tile shows a fixed sentence for each kind of failure. Databricks' own error text never leaves the function; the audit line keeps its error code.

KindWhat the tile says
InvalidThe database could not run the query as written. Check the SQL and its parameters.
RefusedOnly one read-only query (a SELECT) can run through this connector. (Followed by the check that failed, when it adds something.)
ParametersA query parameter is missing or is not a plain value.
CredentialsThe database did not accept the connector's sign-in. An administrator should check the connection's secret.
DeniedThe database refused this query for the connector's database user.
Not foundThe query names a table, view or column the database does not have, or the connector's database user cannot see.
TimeoutThe query did not finish within its N s budget and was cancelled. Narrow it (filters, fewer columns or rows) or run it as a background tile.
UnavailableThe database could not be reached. An administrator should check the connection's host, port and the connector's network settings.
ThrottledThe database is busy (too many connections or queries). Try again shortly.
FailedThe database reported an error running the query.

One exception: when Databricks refuses the token request, the message keeps Databricks' status, error and error_description (never the client id or secret) and says what to change. That is a scope the principal has not been assigned (with the oauth_scope to set), a wrong client id or secret, an unknown scope, a client that may not use client credentials, or a principal that is not in this workspace or has OAuth turned off. The audit line's code is Databricks' error and the status.

Benchmarks

The connector's side only, against the stand-in. Databricks has no second path to compare: these are its standard path's figures.

RowsRows/sMB/sPeak memory
100,0001,018k108.725 MB
1,000,0001,845k196.9286 MB
10,000,0001,895k202.2460 MB

Measured on 2026-12-02 on one laptop (x86, 16 hardware threads), against a local stand-in in a second process that serves external links with Arrow results over loopback. The rows are the kit's typical 12-column row, 107 bytes of Arrow data each, read through the module's handler and streamed as Parquet to a stand-in for S3. MB/s is Arrow data per second; peak memory is how much the process's memory grew while it read the result. This is not a warehouse or its cloud storage: a real warehouse, the network to its storage and Lambda's arm64 cores add their own time. The open streams share fixed memory budgets, so peak memory stays bounded as the rows grow.

Tested

Has run against a real workspace, Databricks Free Edition on AWS, on 2026-12-03: the service principal signed in with the read-only SQL scope (sql:read:restricted-query); the connector listed the workspace's tables; and queries run through StrataLake read their results through external links, following each link's redirect to a Databricks-hosted address. A 68-row grouped query matched the same query run with results = inline, and the whole 1,000-row table matched Databricks' own totals, with no NULLs and not marked as cut. Nothing else has run against a real workspace yet.

Has run in tests, through the function's handler against a local stand-in that answers as Databricks' REST reference documents, with SQLite running the SELECTs and a stand-in for S3:

The OpenTofu (the function's role, no retries, the status writer as the failure destination) is tested with OpenTofu's own tests, including IAM decisions that the role cannot read a credential bound to another module.

Has not run yet, because it needs a real workspace:

AWS services

AWS Lambda (the query function), AWS Secrets Manager (the sign-in), Amazon S3 (results, in your deployment's bucket), Amazon CloudWatch Logs (the audit lines), and optionally Amazon VPC (subnets, a security group, a NAT gateway or an S3 gateway endpoint to the workspace's storage, or AWS PrivateLink), AWS KMS (a customer-managed key on the secret) and Amazon DynamoDB (StrataAPI Manager's registry, with a StrataAPI Manager credential).

Data-source connectors · Data-source connector configuration · Execution types · Build a module · Modules