【发布时间】:2020-10-20 05:30:14
【问题描述】:
就我而言,bq_table_upload() 不起作用,因为文件是 5G。导出为 CSV 并通过 BQ Web UI 上传也因大小而失败。我认为下面的代码曾经是我这样做的方式,但是通过浏览器通过 gar_auth() 进行的身份验证不再适用于我:
library(googleCloudStorageR)
library(bigrquery)
library(googleAuthR)
gcs_global_bucket("XXXXXXXXX")
## custom upload function to ignore quotes and column headers
f <- function(input, output) {
write.table(input, sep = ",", col.names = FALSE, row.names = FALSE,
quote = FALSE, file = output, qmethod = "double")}
## upload files to Google Cloud Storage
gcs_upload(mtcars, name = "mtcars_test1.csv", object_function = f)
## create the schema of the files you just uploaded
user_schema <- schema_fields(mtcars)
## load files from Google Cloud Storage into BigQuery
bqr_upload_data(projectId = "your-project",
datasetId = "test",
tableId = "from_gcs_mtcars",
upload_data = c("gs://XXXXX/mtcars_test1.csv")
schema = user_schema)
有什么解决办法吗?
这是产生的错误:
> gcs_upload(mtcars, name = "mtcars_test1.csv", object_function = f)
2020-06-30 11:49:37 -- File size detected as 1.2 Kb
2020-06-30 11:49:37> No authorization yet in this session!
2020-06-30 11:49:37> NOTE: a .httr-oauth file exists in current working directory.
Run authentication function to use the credentials cached for this session.
Error: Invalid token
然后我尝试使用身份验证
gar_auth()
它会启动一个 Chrome 浏览器窗口,我通常可以通过选择正确的 Google 个人资料进行身份验证,但现在得到“错误 400:invalid_request Missing required parameter: client_id”。
【问题讨论】:
-
您是否尝试过进行部分插入,例如一次插入 100000 行?使用 bq_table_upload 进行第一次迭代,然后使用 bq_table_patch 在循环中插入其他行。
-
@BrunoTremblay 我绝对可以将 bq_table_upload() 用于小型数据帧,但我想如果存在 gcs 解决方案,我宁愿不循环。
-
要使用的正确模式是导出 -> 上传到 GCS -> 导入到 BigQuery(通过 API)。究竟是什么在该管道中不起作用?
-
@GrahamPolley 我添加了我遇到的错误。我相信我正在关注您的链,但无法进行身份验证以执行上传步骤。
标签: r google-bigquery