Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SQL Execution + SQL Connector #37

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: brickster
Title: R interface to Databricks REST 2.0 APIs
Version: 0.2.0
Title: Databricks Utilities in R
Version: 0.2.1
Authors@R:
c(
person(given = "Zac",
Expand All @@ -13,11 +13,12 @@ Authors@R:
email = "[email protected]"),
person("Databricks", role = c("cph", "fnd"))
)
Description: Toolkit to work with Databricks from R
Description: Toolkit to work with Databricks from R.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
arrow,
base64enc,
cli,
curl,
Expand All @@ -29,17 +30,18 @@ Imports:
jsonlite,
magrittr,
purrr,
rlang
reticulate,
R6 (>= 2.4.0),
rlang,
utils
Suggests:
testthat (>= 3.0.0),
DT,
htmltools,
knitr,
magick,
rmarkdown,
rstudioapi,
rvest
Roxygen: list(markdown = TRUE)
rstudioapi
Roxygen: list(markdown = TRUE, r6 = TRUE)
RoxygenNote: 7.2.0
VignetteBuilder: knitr
URL: https://github.com/zacdav-db/brickster
Expand Down
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(DatabricksSqlClient)
export(access_control_req_group)
export(access_control_req_user)
export(access_control_request)
Expand Down Expand Up @@ -92,6 +93,11 @@ export(db_secrets_scope_acl_put)
export(db_secrets_scope_create)
export(db_secrets_scope_delete)
export(db_secrets_scope_list_all)
export(db_sql_client)
export(db_sql_exec_cancel)
export(db_sql_exec_query)
export(db_sql_exec_result)
export(db_sql_exec_status)
export(db_sql_global_warehouse_get)
export(db_sql_query_history)
export(db_sql_warehouse_create)
Expand All @@ -114,6 +120,7 @@ export(db_workspace_list)
export(db_workspace_mkdirs)
export(db_wsid)
export(dbfs_storage_info)
export(determine_brickster_venv)
export(docker_image)
export(email_notifications)
export(file_storage_info)
Expand All @@ -122,6 +129,7 @@ export(get_and_start_cluster)
export(get_and_start_warehouse)
export(git_source)
export(init_script_info)
export(install_db_sql_connector)
export(is.access_control_req_group)
export(is.access_control_req_user)
export(is.access_control_request)
Expand Down Expand Up @@ -168,6 +176,7 @@ export(new_cluster)
export(notebook_task)
export(open_workspace)
export(pipeline_task)
export(py_db_sql_connector)
export(python_wheel_task)
export(remove_lib_path)
export(s3_storage_info)
Expand All @@ -177,10 +186,13 @@ export(spark_jar_task)
export(spark_python_task)
export(spark_submit_task)
export(wait_for_lib_installs)
import(R6)
import(arrow)
import(cli)
import(httr2)
importFrom(glue,glue)
importFrom(magrittr,`%>%`)
importFrom(rlang,.data)
importFrom(stats,setNames)
importFrom(utils,object.size)
importFrom(utils,packageVersion)
18 changes: 18 additions & 0 deletions R/databricks-helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on_databricks <- function() {
dbr <- Sys.getenv("DATABRICKS_RUNTIME_VERSION")
dbr != ""
}

#' Determine brickster virtualenv
#'
#' @details Returns `NULL` when running within Databricks,
#' otherwise `"r-brickster"`
#'
#' @export
determine_brickster_venv <- function() {
if (on_databricks()) {
NULL
} else {
"r-brickster"
}
}
11 changes: 10 additions & 1 deletion R/package-auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ db_host <- function(id = NULL, prefix = NULL, profile = getOption("db_profile",

if (is.null(id) && is.null(prefix)) {
host <- read_env_var(key = "host", profile = profile)
parsed_url <- httr2::url_parse(host)

# inject scheme if not present then re-build with https
if (is.null(parsed_url$schema)) {
parsed_url$scheme <- "https"
host <- httr2::url_build(parsed_url)
}
host <- httr2::url_parse(host)$hostname

} else {
# otherwise construct host string
host <- paste0("https://", prefix, id, ".cloud.databricks.com")
host <- paste0(prefix, id, ".cloud.databricks.com")
}

host
Expand Down
16 changes: 13 additions & 3 deletions R/request-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@
#'
#' @return request
#' @import httr2
#' @importFrom utils packageVersion
#' @importFrom magrittr `%>%`
db_request <- function(endpoint, method, version = NULL, body = NULL, host, token, ...) {

req <- httr2::request(base_url = paste0(host, "api", "/", version, "/")) %>%
url <- list(
scheme = "https",
hostname = host,
path = paste0("/api/", version)
)

url <- httr2::url_build(url)
user_agent_str <- paste0("brickster/", utils::packageVersion("brickster"))

req <- httr2::request(base_url = url) %>%
httr2::req_auth_bearer_token(token) %>%
httr2::req_headers("User-Agent" = "brickster/1.0") %>%
httr2::req_user_agent(string = "brickster/1.0") %>%
httr2::req_headers("User-Agent" = user_agent_str) %>%
httr2::req_user_agent(string = user_agent_str) %>%
httr2::req_url_path_append(endpoint) %>%
httr2::req_method(method) %>%
httr2::req_retry(max_tries = 3, backoff = ~ 2)
Expand Down
Loading
Loading