【发布时间】:2020-06-19 20:29:56
【问题描述】:
我正在尝试运行一个简单的测试cloud function,在其中创建一个BigQuery 表并插入一个值。我收到的错误听起来像是我需要导入pyarrow,所以我试过这样做,但我一直收到同样的错误。当我在本地运行等效脚本时,没有任何问题,表已创建,我什至不需要导入pyarrow。我在这里想念什么?
error:
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'. pyarrow or fastparquet is required for parquet support
main.py:
import pandas as pd
from google.cloud import bigquery
import pyarrow
def main_func(data, context):
df = pd.DataFrame({'Test': ['Success']})
client = bigquery.Client()
dataset_id = #removed here but specified in the real code
dataset = bigquery.Dataset(dataset_id)
dataset.location = #removed here but specified in the real code
dataset = client.create_dataset(dataset, exists_ok=True)
print("Created dataset {}.{}".format(client.project, dataset.dataset_id))
table_id = #removed here but specified in the real code
job_config = bigquery.LoadJobConfig(
schema=[
bigquery.SchemaField("Test", bigquery.enums.SqlTypeNames.STRING),
],
write_disposition="WRITE_TRUNCATE",
)
job = client.load_table_from_dataframe(
df, table_id, job_config = job_config
)
job.result()
requirements.txt:
pandas
google-cloud-bigquery
pyarrow
【问题讨论】:
-
我发现Pandas由于兼容性问题没有检测到任何
pyarrow<0.4,你可以尝试在你的requirements.txt中添加pyarrow>=0.4 -
老兄!刚刚试过,效果很好!添加一个答案,我会接受它!谢谢:)
标签: python pandas google-cloud-platform google-bigquery google-cloud-functions