2016-11-08 50 views
0

I以下の機能があります。BigQueryのクエリ応答「jobComplete」:偽

def query_big_query(query_data, project_id): 
    credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials_bq.json') 
    bigquery_service = build('bigquery', 'v2', credentials=credentials) 
    try: 
     query_request = bigquery_service.jobs() 
     query_response = query_request.query(projectId=project_id, body=query_data).execute() 
     return query_response 
    except HttpError as error: 
     print ('Error :{}'.format(error.content)) 
     raise error 

は、しかし、クエリの一部は、クエリは少し時間がかかるbacause、データを返すと、次の文字列を返しません。

{u'kind': u'bigquery#queryResponse', u'jobComplete': False, u'jobReference': {u'projectId': u'od', u'jobId': u'job_5wAuC'}} 

ジョブが完了するまで(真)にはどうすればいいですか?または、結果を別の呼び出しとして要求する必要がありますか?

答えて

0

これを試してみてください:

response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute() 
while not response['jobComplete']: 
    print "waiting for response..." 
    time.sleep(1) 
    response = bigquery_service.jobs().getQueryResults(projectId=my_project_id, jobId=my_job_id).execute() 
return response 
関連する問題