将表从 google bigquery 导出到 google 存储
Posted
技术标签:
【中文标题】将表从 google bigquery 导出到 google 存储【英文标题】:export tables from google bigquery to google storage 【发布时间】:2016-10-17 14:37:11 【问题描述】:我是 bigQuery 的新手。我需要将表从 BigQuery 导出到谷歌存储。 目前,我可以按数据集列出所有表。 有没有一些人可以帮助我如何导出表格? 我的python代码如下:
#!/usr/bin/env python
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from bigquery_client import client
credentials = GoogleCredentials.get_application_default()
service = discovery.build('bigquery', 'v2', credentials=credentials)
# * Project ID of the datasets to be listed
projectId = 'xxxxxxxxx'
datasets = service.datasets()
request = datasets.list(projectId=projectId)
response = request.execute()
for dataset in response['datasets']:
datasetId = dataset['datasetReference']['datasetId']
tables = service.tables()
request = tables.list(projectId=projectId, datasetId=datasetId)
response = request.execute()
if 'tables' in response :
for table in response['tables']:
print ('Dataset name treated is :' + '%s' % dataset['datasetReference']['datasetId'])
print ('%s' % dataset['datasetReference']['datasetId'])
print ('Is table number:' + '%s' % table['tableReference']['tableId'])
谢谢
【问题讨论】:
【参考方案1】:docs page 上有一个完整的 Python 示例
包括此处以供将来参考:
def export_data_to_gcs(dataset_name, table_name, destination):
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(table_name)
job = bigquery_client.extract_table(
table, destination)
job.result()
print('Exported : to '.format(
dataset_name, table_name, destination))
【讨论】:
以上是关于将表从 google bigquery 导出到 google 存储的主要内容,如果未能解决你的问题,请参考以下文章