这是一个简单的代码,可以将Biq查询以CSV格式导出到Google存储空间
def export_data():
client = bigquery.Client()
project = 'xxxxx'
dataset_id = 'xxx'
table_id = 'xxx'
bucket_name = 'xxx'
destination_uri = 'gs://{}/{}'.format(bucket_name, 'EXPORT_FILE.csv')
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
extract_job = client.extract_table(
table_ref,
destination_uri,
# Location must match that of the source table.
location='EU') # API request
extract_job.result() # Waits for job to complete.
print('Exported {}:{}.{} to {}'.format(
project, dataset_id, table_id, destination_uri))
它非常适合常规表,但是当我尝试从已保存的表VIEW中导出数据时,由于以下错误而失败:
BadRequest: 400 Using table xxx:xxx.xxx@123456 is not allowed for this operation because of its type. Try using a different table that is of type TABLE.
是否存在从表视图导出数据的任何方式?
我想要实现的是,以CSV格式从BigQuery获取数据,并将其上传到Google Analytics(分析)产品数据
答案 0 :(得分:3)
BigQuery视图are subject to a few limitations:
我没有在答案中发布超过10多个其他限制,因为它们可能会更改。按照link阅读所有内容。
您需要查询视图并将结果写入目标表,然后在目标表上发布导出作业。