original_docstring: 
      extract BQ table to a file in google cloud storage.
      
docstring: extract BQ table to a file in google cloud storage.
docstring_tokens: extract BQ table to a file in google cloud storage .
code: def extract_table_to_gs(dataset_id, table_id, gsfn, format=None, do_gzip=False, wait=True, 
                          verbose=False,
                          project_id=DEFAULT_PROJECT_ID):
      '''
      extract BQ table to a file in google cloud storage.
      '''
  
      project_ref = dict(projectId=project_id)
      config = {'extract': {'sourceTable': {'projectId': project_id,
                                            'datasetId': dataset_id,
                                            'tableId': table_id
                                            },
                            'destinationUris': [ gsfn ],
                            'destinationFormat': 'NEWLINE_DELIMITED_JSON',
                            'compression': 'GZIP' if do_gzip else "NONE",
                            }
                }
  
      if format=='csv':
          config['extract']['destinationFormat'] = 'CSV'
  
      job_id = 'load_%s_%d' % (table_id, time.time())
      job_ref = {'jobId': job_id,
                 'projectId': project_id}
      
      job = {'jobReference': job_ref, 'configuration': config}
      
      print "[bqutil] extracting table %s to %s, running job %s" % (table_id, gsfn, job_id)
      sys.stdout.flush()
  
      if verbose:
          print job
  
      try:
          job = jobs.insert(body=job, **project_ref).execute()
      except Exception as err:
          print "[bqutil] oops!  Failed to insert job=%s" % job
          raise
  
      if verbose:
          print "job=", json.dumps(job, indent=4)
        
      if verbose:
          job_list = jobs.list( stateFilter=['pending', 'running'], **project_ref).execute()
          print "job list: ", job_list
  
      if not wait:
          return
  
      nerr = 0
      while job['status']['state'] <> 'DONE':
          try:
              job = jobs.get(**job_ref).execute()
          except Exception as err:
              if "Internal Error" in str(err):
                  nerr += 1
                  if nerr > 10:
                      raise
                  time.sleep(10)
                  continue
  
      status = job['status']
      print "[bqutil] job status: ", status
  
      if 'errors' in status:
          print "[bqutil] ERROR!  ", status['errors']
          print "job = ", json.dumps(job, indent=4)
          raise Exception('BQ Error creating table')
code_tokens: def extract_table_to_gs ( dataset_id , table_id , gsfn , format = None , do_gzip = False , wait = True , verbose = False , project_id = DEFAULT_PROJECT_ID ) : project_ref = dict ( projectId = project_id ) config = { 'extract' : { 'sourceTable' : { 'projectId' : project_id , 'datasetId' : dataset_id , 'tableId' : table_id } , 'destinationUris' : [ gsfn ] , 'destinationFormat' : 'NEWLINE_DELIMITED_JSON' , 'compression' : 'GZIP' if do_gzip else "NONE" , } } if format == 'csv' : config [ 'extract' ] [ 'destinationFormat' ] = 'CSV' job_id = 'load_%s_%d' % ( table_id , time . time ( ) ) job_ref = { 'jobId' : job_id , 'projectId' : project_id } job = { 'jobReference' : job_ref , 'configuration' : config } print "[bqutil] extracting table %s to %s, running job %s" % ( table_id , gsfn , job_id ) sys . stdout . flush ( ) if verbose : print job try : job = jobs . insert ( body = job , ** project_ref ) . execute ( ) except Exception as err : print "[bqutil] oops!  Failed to insert job=%s" % job raise if verbose : print "job=" , json . dumps ( job , indent = 4 ) if verbose : job_list = jobs . list ( stateFilter = [ 'pending' , 'running' ] , ** project_ref ) . execute ( ) print "job list: " , job_list if not wait : return nerr = 0 while job [ 'status' ] [ 'state' ] <> 'DONE' : try : job = jobs . get ( ** job_ref ) . execute ( ) except Exception as err : if "Internal Error" in str ( err ) : nerr += 1 if nerr > 10 : raise time . sleep ( 10 ) continue status = job [ 'status' ] print "[bqutil] job status: " , status if 'errors' in status : print "[bqutil] ERROR!  " , status [ 'errors' ] print "job = " , json . dumps ( job , indent = 4 ) raise Exception ( 'BQ Error creating table' )
short_docstring: extract BQ table to a file in google cloud storage.
short_docstring_tokens: extract BQ table to a file in google cloud storage .
comment: '''
      extract BQ table to a file in google cloud storage.
      '''