Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07e92d7

Browse filesBrowse files
tswastJon Wayne Parrott
authored andcommitted
BigQuery - use new QueryJob.results() method. (GoogleCloudPlatform#555)
This method was added in googleapis/google-cloud-python#2083. I can remove my hack now.
1 parent ea67314 commit 07e92d7
Copy full SHA for 07e92d7

File tree

Expand file treeCollapse file tree

1 file changed

+11
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-19
lines changed

‎bigquery/cloud-client/async_query.py

Copy file name to clipboardExpand all lines: bigquery/cloud-client/async_query.py
+11-19Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
from 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+
3343
def 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-
7567
if __name__ == '__main__':
7668
parser = argparse.ArgumentParser(
7769
description=__doc__,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.