File tree Expand file tree Collapse file tree 1 file changed +11
-19
lines changed
Expand file tree Collapse file tree 1 file changed +11
-19
lines changed Original file line number Diff line number Diff line change 3030from google .cloud import bigquery
3131
3232
33+ def wait_for_job (job ):
34+ while True :
35+ job .reload () # Refreshes the state via a GET request.
36+ if job .state == 'DONE' :
37+ if job .error_result :
38+ raise RuntimeError (job .error_result )
39+ return
40+ time .sleep (1 )
41+
42+
3343def async_query (query ):
3444 client = bigquery .Client ()
3545 query_job = client .run_async_query (str (uuid .uuid4 ()), query )
@@ -38,16 +48,8 @@ def async_query(query):
3848
3949 wait_for_job (query_job )
4050
41- # Manually construct the QueryResults.
42- # TODO: The client library will provide a helper method that does this.
43- # https://github.com/GoogleCloudPlatform/gcloud-python/issues/2083
44- query_results = bigquery .query .QueryResults ('' , client )
45- query_results ._properties ['jobReference' ] = {
46- 'jobId' : query_job .name ,
47- 'projectId' : query_job .project
48- }
49-
5051 # Drain the query results by requesting a page at a time.
52+ query_results = query_job .results ()
5153 page_token = None
5254
5355 while True :
@@ -62,16 +64,6 @@ def async_query(query):
6264 break
6365
6466
65- def wait_for_job (job ):
66- while True :
67- job .reload () # Refreshes the state via a GET request.
68- if job .state == 'DONE' :
69- if job .error_result :
70- raise RuntimeError (job .error_result )
71- return
72- time .sleep (1 )
73-
74-
7567if __name__ == '__main__' :
7668 parser = argparse .ArgumentParser (
7769 description = __doc__ ,
You can’t perform that action at this time.
0 commit comments