Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将表从google bigquery导出到google存储_Python_Google Bigquery - Fatal编程技术网

Python 将表从google bigquery导出到google存储

Python 将表从google bigquery导出到google存储,python,google-bigquery,Python,Google Bigquery,我是bigQuery的新手。我需要将表从BigQuery导出到google存储。 目前,我可以按数据集列出所有表。 有酒可以帮我吗?我怎样才能导出表格? 我的python代码如下: #!/usr/bin/env python from googleapiclient import discovery from oauth2client.client import GoogleCredentials from bigquery_client import client credentials

我是bigQuery的新手。我需要将表从BigQuery导出到google存储。 目前,我可以按数据集列出所有表。 有酒可以帮我吗?我怎样才能导出表格? 我的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'])

谢谢

上有一个完整的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))