From ef6dc0e03a06fcd32074a4d72cca12fd009ac4b8 Mon Sep 17 00:00:00 2001 From: Alejandro Palacio <64808307+apalacio9502@users.noreply.github.com> Date: Mon, 10 Jun 2024 08:01:05 -0500 Subject: [PATCH] Write Parquet file into a memory buffer (#612) And drop `export_parquet()` wrapper --- DESCRIPTION | 4 +++- R/bq-perform.R | 18 ++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 36149355..19dab848 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Imports: prettyunits, rlang (>= 1.1.0), tibble, - nanoparquet + nanoparquet (> 0.2.0) Suggests: blob, covr, @@ -41,6 +41,8 @@ Suggests: testthat (>= 3.1.5), wk (>= 0.3.2), withr +Remotes: + r-lib/nanoparquet LinkingTo: cli, cpp11, diff --git a/R/bq-perform.R b/R/bq-perform.R index f6b4e1a7..dfa504e6 100644 --- a/R/bq-perform.R +++ b/R/bq-perform.R @@ -157,9 +157,10 @@ bq_perform_upload <- function(x, values, "content" = export_json(values) ) } else { + # https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-parquet?hl=es-419 media <- list( "type" = "application/vnd.apache.parquet", - "content" = export_parquet(values) + "content" = nanoparquet::write_parquet(values, ":raw:") ) } @@ -199,21 +200,6 @@ export_json <- function(values) { rawToChar(rawConnectionValue(con)) } -# https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-parquet?hl=es-419 -export_parquet <- function(values) { - - tmpfile <- tempfile(fileext = ".parquet") - - defer(unlink(tmpfile)) - - # write to disk - nanoparquet::write_parquet(values, tmpfile) - - # read back results - readBin(tmpfile, what = "raw", n = file.info(tmpfile)$size) - -} - #' @export #' @name api-perform #' @param source_uris The fully-qualified URIs that point to your data in