python - 从 Google Cloud Storage 读取时指定读取缓冲区大小
问题描述
我正在尝试使用 cloudstorage 库打开我在 Google Cloud Storage 中的文件。我收到模块 cloudtorage 没有属性“打开”的错误。
当我将文件从 Google Cloud Storage 加载到 Google BigQuery 时,我想指定读取缓冲区大小。这是我希望使用的功能。参数需要一个类似对象的文件。
Client.load_table_from_file(file_obj, destination, rewind=False, size=None, num_retries=6, job_id=None, job_id_prefix=None, location=None, project=None, job_config=None)[source]
从类文件对象上传此表的内容。
有没有其他方法可以将 Cloud Storage 文件作为对象传递给这个方法?或者也许是另一种在指定读取缓冲区大小的同时将文件从云存储加载到 Google BigQuery 的方法。
from google.cloud import bigquery
from google.cloud import storage
import cloudstorage as gcs
def hello_gcs(event, context):
gcs_file = gcs.open('no-trigger/transaction.csv')
job_config = bigquery.LoadJobConfig()
job_config.autodetect = False
job_config.max_bad_records=1
job_config.create_disposition = 'CREATE_IF_NEEDED'
job_config.source_format = bigquery.SourceFormat.CSV
load_job = bclient.load_table_from_file(
gcs_file,
dataset_ref.table(temptablename),
location='asia-northeast1',
size=2147483648,
job_config=job_config) # API request
解决方案
推荐阅读
- google-bigquery - BigQuery 如何使用 MERGE 加载数组列
- selenium-webdriver - 不应该 @Test 与“alwaysRun=true”运行,而不管它属于什么方法或组”?
- spring-mvc - java.lang.IllegalStateException:Bean 名称“UserDto”的 BindingResult 和普通目标对象都不能用作请求属性
- azure - 维护密切反映生产 AAD 的开发 Azure Active Directory (AAD) 的最佳实践?
- css - 将滚动应用到 flex 容器的特定部分
- c - 如何在我的代码逻辑中找到错误?
- c# - 从远程启动的进程访问 Remote PC 注册表
- r - R dplyr::summarize groups by user defined functions
- dialogflow-es - 有什么方法可以从对话框流中获取“类型”的文本
- java - 我想在处理中使用 keyPressed() 稍微移动一个椭圆,但是当我这样做时,它会添加另一个椭圆而不是去掉一个