首页 > 解决方案 > 从 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

标签: pythongoogle-cloud-platformgoogle-cloud-storage

解决方案


推荐阅读