We are excited to announce the general availability of the Databricks SQL Driver for GO. This follows the recent general availability of Databricks SQL Driver for NodeJS and the earlier Databricks SQL Connector for Python. GO developers can now easily build data applications on the lakehouse in GO.
By providing a native driver in pure GO compliant with the database/sql package, we enable a simple developer experience that API developers already know. These apps can benefit from Go's speed as a compiled language to fetch larger amounts of data.
In this blog post, we will run through some examples of connecting to Databricks and running queries against a sample dataset.
Simple package import
With this GO driver, there's no need to deal with ODBC/JDBC driver dependencies. To get started, simply import database/sql and Databricks SQL Driver fo GO as follows:
package main
import (
"database/sql"
"fmt"
_ "github.com/databricks/databricks-sql-go"
)
Setting up connection
The connector works with SQL Warehouses as well as All Purpose Clusters. In this example, we show you how to connect to and run a query on a SQL Warehouse. To establish a connection, we import the connector and pass in connection and authentication information. You can authenticate using a Databricks personal access token (PAT) or a Microsoft Azure active directory (AAD) token.
func main() {
dsn := "token://dapi***@host*****.databricks.com/sql/1.0/warehouses/***"
db, err := sql.Open("databricks", dsn)
if err != nil {
panic(err)
}
Querying data
The following example retrieves a list of trips from the NYC taxi sample dataset and prints trip distances the result to the console.
rows, err := db.Query("SELECT trip_distance FROM samples.nyctaxi.trips")
defer rows.Close()
var stringVal string
for rows.Next() {
err := rows.Scan(&stringVal)
if err != nil {
panic(err)
}
fmt.Println(stringVal)
}
}
Check our documentation for more examples & full API reference.
A bright future for Go developers on the lakehouse
We're happy to announce that our GO driver is open source on Github. We welcome contributions from the community. We're pleased to have worked with several partners while developing this driver, especially Sigma who are using this new driver to bring their powerful BI and analytics capabilities to Databricks customers.
We're even more excited about what our customers will build with the Databricks SQL Driver for GO! Please try out the driver and let us know what you think on Github. We would love to hear from you on what you would like us to support.