databricks/databricks-sql-go
Go
Captured source
source ↗databricks/databricks-sql-go
Description: Golang database/sql driver for Databricks SQL.
Language: Go
License: Apache-2.0
Stars: 50
Forks: 62
Open issues: 56
Created: 2022-05-18T17:36:43Z
Pushed: 2026-06-04T14:41:15Z
Default branch: main
Fork: no
Archived: no
README:
Databricks SQL Driver for Go
Description
This repo contains a Databricks SQL Driver for Go's database/sql package. It can be used to connect and query Databricks clusters and SQL Warehouses.
Documentation
See doc.go for full documentation or the Databrick's documentation for SQL Driver for Go.
Usage
import (
"context"
"database/sql"
_ "github.com/databricks/databricks-sql-go"
)
db, err := sql.Open("databricks", "token:********@********.databricks.com:443/sql/1.0/endpoints/********")
if err != nil {
panic(err)
}
defer db.Close()
rows, err := db.QueryContext(context.Background(), "SELECT 1")
defer rows.Close()Additional usage examples are available here.
Connecting with DSN (Data Source Name)
The DSN format is:
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?param=value
You can set query timeout value by appending a timeout query parameter (in seconds) and you can set max rows to retrieve per network request by setting the maxRows query parameter:
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?timeout=1000&maxRows=1000
You can turn on Cloud Fetch (now enabled by default) to increase the performance of extracting large query results by fetching data in parallel via cloud storage (more info here). You can also set the number of concurrently fetching goroutines by setting the maxDownloadThreads query parameter (default is 10):
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?useCloudFetch=true&maxDownloadThreads=3
To disable Cloud Fetch (e.g., when handling smaller datasets or to avoid additional overhead), append useCloudFetch=false:
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?useCloudFetch=false
Telemetry Configuration (Optional)
The driver includes optional telemetry to help improve performance and reliability. Telemetry is disabled by default and requires explicit opt-in.
Opt-in to telemetry (respects server-side feature flags):
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?enableTelemetry=true
Opt-out of telemetry (explicitly disable):
token:[your token]@[Workspace hostname]:[Port number][Endpoint HTTP Path]?enableTelemetry=false
What data is collected:
- ✅ Query latency and performance metrics
- ✅ Error codes (not error messages)
- ✅ Feature usage (CloudFetch, LZ4, etc.)
- ✅ Driver version and environment info
What is NOT collected:
- ❌ SQL query text
- ❌ Query results or data values
- ❌ Table/column names
- ❌ User identities or credentials
Telemetry has ), dbsql.WithPort(), dbsql.WithHTTPPath(), dbsql.WithAccessToken() ) if err != nil { log.Fatal(err) } db := sql.OpenDB(connector) defer db.Close()
View `doc.go` or `connector.go` to understand all the functional options available when creating a new connector object. ## Develop ### Lint We use `golangci-lint` as the lint tool. If you use vs code, just add the following settings:
{ "go.lintTool": "golangci-lint", "go.lintFlags": [ "--fast" ] }
### Unit Tests
go test
## Issues If you find any issues, feel free to create an issue or send a pull request directly. ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) ## License [Apache 2.0](https://github.com/databricks/databricks-sql-go/blob/main/LICENSE)