【问题标题】:Loading local file using Cloud Functions to BigQuery returns OSError: [Errno 30] `Read-only file system:使用 Cloud Functions 将本地文件加载到 BigQuery 会返回 OSError: [Errno 30] `Read-only file system:
【发布时间】:2019-10-17 11:40:19
【问题描述】:

我正在尝试将 Dataframe 加载到 BigQuery 中。我这样做如下:

# Prepare temp file to stream from local file
temp_file = table_name + '-' + str(timestamp_in_ms())
df.to_csv(temp_file, index=None, header=True)

# Define job_config
job_config = bigquery.LoadJobConfig()
job_config.schema = schema
job_config.skip_leading_rows = 1
job_config.source_format = bigquery.SourceFormat.CSV

# Create job to load data into table
with open(temp_file, "r+b") as source_file:
    load_job = client.load_table_from_file(source_file, dataset_ref.table(table_name), job_config=job_config)

这在本地开发中运行良好,但是当我部署 Cloud Function 时,它返回以下错误:

OSError: [Errno 30] Read-only file system: '{temp_file}'

这发生在open(temp_file, "r+b") as source_file:一行

为什么无法读取云函数临时存储上的本地文件?出了什么问题?

【问题讨论】:

    标签: google-bigquery google-cloud-functions


    【解决方案1】:

    可能你没有指定文件夹 /tmp

    本地磁盘

    Cloud Functions 提供对本地磁盘挂载点 (/tmp) 的访问 这被称为“tmpfs”卷,其中数据写入该卷 存储在内存中。没有与此相关的具体费用 但是将数据写入 /tmp 挂载点会消耗内存 为该功能提供的资源。

    如上所述:https://cloud.google.com/functions/pricing

    【讨论】:

    • 唯一的困难是当你在本地测试它时,你需要做tmp/而不是/tmp
    猜你喜欢
    • 1970-01-01
    • 2021-11-19
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    相关资源
    最近更新 更多