【发布时间】:2018-08-13 14:01:40
【问题描述】:
这是从 Biq Query 以 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 分析产品数据
【问题讨论】:
标签: python google-analytics google-bigquery google-analytics-api