Skip to content

Commit

Permalink
Write Parquet file into a memory buffer (#612)
Browse files Browse the repository at this point in the history
And drop `export_parquet()` wrapper
  • Loading branch information
apalacio9502 authored Jun 10, 2024
1 parent 3642c14 commit ef6dc0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Imports:
prettyunits,
rlang (>= 1.1.0),
tibble,
nanoparquet
nanoparquet (> 0.2.0)
Suggests:
blob,
covr,
Expand All @@ -41,6 +41,8 @@ Suggests:
testthat (>= 3.1.5),
wk (>= 0.3.2),
withr
Remotes:
r-lib/nanoparquet
LinkingTo:
cli,
cpp11,
Expand Down
18 changes: 2 additions & 16 deletions R/bq-perform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
)
}

Expand Down Expand Up @@ -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
Expand Down

2 comments on commit ef6dc0e

@hadley
Copy link
Member

@hadley hadley commented on ef6dc0e Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apalacio9502 any idea what's going on with the live API action failure? It looks like maybe it's just a random failure?

@apalacio9502
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hadley,

#613 This pull request aims to address the error encountered in the live API.

Regards,

Please sign in to comment.