【发布时间】:2021-08-14 22:58:34
【问题描述】:
我有一个 bigquery 表 - 我想将它提取到云函数内的 pandas 数据帧中,然后在头文件中进行一些更改,然后将其保存到云存储中。不幸的是我的功能不起作用,任何人都可以看到可能是什么问题。我需要使用大查询提取作业还是我的想法也有效?
import base64
import pandas as pd
from google.cloud import bigquery
def extract_partial_return(event, context):
client = bigquery.Client()
bucket_name = "abc_test"
project = "bq_project"
dataset_id = "bq_dataset"
table_id = "Partial_Return_Table"
sql = """
SELECT * FROM `bq_project.bq_dataset.Partial_Return_Table`
"""
# Running the query and putting the results directly into a df
df = client.query(sql).to_dataframe()
df.columns = ["ga:t_Id", "ga:product", "ga:quantity"]
destination_uri = (
"gs://abc_test/Exports/Partial_Return_Table.csv"
)
df.to_csv(destination_uri)
我的 requirements.txt 看起来像这样
# Function dependencies, for example:
# package>=version
google-cloud-bigquery
pandas
pyarrow
【问题讨论】:
-
“我的功能不工作”是什么意思?你期望的结果是什么?你看到了什么?
标签: google-cloud-platform google-bigquery google-cloud-functions google-cloud-storage