Linked Questions

Popular Questions

export tables from google bigquery to google storage

Asked by At

I'm new on bigQuery. I need to export tables from BigQuery to google storage. For the moment, I can list all tables by dataset. Does some boody can help me with how can I export then tables? My python code is below :

#!/usr/bin/env python

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from bigquery_client import client

credentials = GoogleCredentials.get_application_default()
service ='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'])


Related Questions