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

Fixing volume write function adding bytes #39

Merged
merged 2 commits into from
Mar 25, 2024
Merged
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
Binary file modified .DS_Store
Binary file not shown.
7 changes: 3 additions & 4 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
Version: 0.2.1
Authors@R:
c(
person(given = "Zac",
Expand All @@ -13,7 +13,7 @@ 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
Expand All @@ -32,15 +32,14 @@ Imports:
rlang
Suggests:
testthat (>= 3.0.0),
DT,
htmltools,
knitr,
magick,
rmarkdown,
rstudioapi,
rvest
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.3.1
VignetteBuilder: knitr
URL: https://github.com/zacdav-db/brickster
Config/testthat/edition: 3
40 changes: 13 additions & 27 deletions R/volume-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ db_volume_read <- function(path, destination,
if (perform_request) {
req %>%
httr2::req_error(body = db_req_error_body) %>%
# uncomment when available via cran
# httr2::req_progress(type = "down") %>%
httr2::req_progress(type = "down") %>%
httr2::req_perform(path = destination) %>%
httr2::resp_check_status()
} else {
Expand Down Expand Up @@ -75,39 +74,24 @@ db_volume_delete <- function(path,
#' Upload a file to volume filesystem.
#'
#' @param file Path to a file on local system, takes precedent over `path`.
#' @param contents String that is base64 encoded.
#' @param overwrite Flag (Default: `FALSE`) that specifies whether to overwrite
#' existing files.
#' @inheritParams db_volume_read
#' @inheritParams auth_params
#'
#' @details
#' Either `contents` or `file` must be specified. `file` takes precedent over
#' `contents` if both are specified.
#'
#' Uploads a file of up to 2 GiB.
#' Uploads a file of up to 5 GiB.
#'
#' @family Volumes FileSystem API
#'
#' @export
db_volume_write <- function(path, file = NULL, contents = NULL, overwrite = FALSE,
host = db_host(), token = db_token()) {

body <- list(
path = path,
overwrite = ifelse(overwrite, "true", "false")
)
db_volume_write <- function(path, file = NULL, overwrite = FALSE,
host = db_host(), token = db_token(), perform_request = TRUE) {

# file takes priority, so don't bother if file is also specified
if (!is.null(contents) && is.null(file)) {
# contents must be base64 encoded string
body$contents <- base64enc::base64encode(base::charToRaw(contents))
} else if (!is.null(file)) {
body$contents <- curl::form_file(path = file)
} else {
if (is.null(file)) {
stop(cli::format_error(c(
"Nothing to upload:",
"x" = "Either `file` or `contents` must be specified."
"x" = "Either `file` must be specified."
)))
}

Expand All @@ -119,13 +103,15 @@ db_volume_write <- function(path, file = NULL, contents = NULL, overwrite = FALS
token = token
)

req <- req %>%
httr2::req_url_query(
overwrite = ifelse(overwrite, "true", "false")
)

req %>%
httr2::req_body_multipart(
path = body$path,
contents = body$contents,
overwrite = body$overwrite
) %>%
httr2::req_body_file(file) %>%
httr2::req_error(body = db_req_error_body) %>%
httr2::req_progress(type = "up") %>%
httr2::req_perform() %>%
httr2::resp_check_status()

Expand Down
2 changes: 1 addition & 1 deletion man/db_cluster_create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_edit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_events.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_list_node_types.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_list_zones.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_perm_delete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_pin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_resize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_restart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_runtime_versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_start.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_terminate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_cluster_unpin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_delete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_reset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_run_now.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_runs_cancel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_runs_delete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_runs_export.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_runs_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_runs_submit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_jobs_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/db_mlflow_model_approve_transition_req.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading