使用Cloud Functions将本地文件加载到BigQuery会返回OSError:[Errno 30]`只读文件系统:

时间:2019-10-17 11:40:19

标签: google-bigquery google-cloud-functions

我正在尝试将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:

一起发生

为什么它不能读取Cloud Function临时存储上的本地文件?出了什么问题?

1 个答案:

答案 0 :(得分:2)

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

本地磁盘

  

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

如以下解释:https://cloud.google.com/functions/pricing