
Connect to Databricks clusters and SQL warehouses via the Databricks ODBC driver.
In particular, the custom dbConnect()
method for the Databricks ODBC driver
implements a subset of the Databricks client unified authentication
model, with support for personal access tokens, OAuth machine-to-machine
credentials, and OAuth user-to-machine credentials supplied via Posit
Workbench or the Databricks CLI on desktop. It can also detect viewer-based
credentials on Posit Connect if the connectcreds package is
installed. All of these credentials are detected automatically if present
using standard environment variables.
In addition, on macOS platforms, the dbConnect()
method will check
for irregularities with how the driver is configured,
and attempt to fix in-situ, unless the odbc.no_config_override
environment variable is set.
databricks()# S4 method for DatabricksOdbcDriver
dbConnect(
drv,
httpPath,
workspace = Sys.getenv("DATABRICKS_HOST"),
useNativeQuery = TRUE,
driver = NULL,
HTTPPath,
uid = NULL,
pwd = NULL,
...
)
An OdbcConnection
object with an active connection to a Databricks
cluster or SQL warehouse.
An object that inherits from DBI::DBIDriver, or an existing DBI::DBIConnection object (in order to clone an existing connection).
To query a cluster, use the HTTP Path value found
under Advanced Options > JDBC/ODBC
in the Databricks UI. For SQL
warehouses, this is found under Connection Details
instead.
The URL of a Databricks workspace, e.g.
"https://example.cloud.databricks.com"
.
Suppress the driver's conversion from ANSI SQL 92 to
HiveSQL? The default (TRUE
), gives greater performance but means that
paramterised queries (and hence dbWriteTable()
) do not work.
The name of the Databricks ODBC driver, or NULL
to use the
default name.
Manually specify a username and password for authentication. Specifying these options will disable automated credential discovery.
Further arguments passed on to dbConnect()
.
if (FALSE) {
DBI::dbConnect(
odbc::databricks(),
httpPath = "sql/protocolv1/o/4425955464597947/1026-023828-vn51jugj"
)
# Use credentials from the viewer (when possible) in a Shiny app
# deployed to Posit Connect.
library(connectcreds)
server <- function(input, output, session) {
conn <- DBI::dbConnect(
odbc::databricks(),
httpPath = "sql/protocolv1/o/4425955464597947/1026-023828-vn51jugj"
)
}
}
Run the code above in your browser using DataLab