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 30
30
from google .cloud import bigquery
31
31
32
32
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
+
33
43
def async_query (query ):
34
44
client = bigquery .Client ()
35
45
query_job = client .run_async_query (str (uuid .uuid4 ()), query )
@@ -38,16 +48,8 @@ def async_query(query):
38
48
39
49
wait_for_job (query_job )
40
50
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
-
50
51
# Drain the query results by requesting a page at a time.
52
+ query_results = query_job .results ()
51
53
page_token = None
52
54
53
55
while True :
@@ -62,16 +64,6 @@ def async_query(query):
62
64
break
63
65
64
66
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
-
75
67
if __name__ == '__main__' :
76
68
parser = argparse .ArgumentParser (
77
69
description = __doc__ ,
You can’t perform that action at this time.
0 commit comments