Reputation: 31
According to the BigQuery documentation listed at https://cloud.google.com/bigquery/querying-data#asynchronous-queries:
There are two types of querying via the BigQuery API. Synchronous and Asynchronous. Async works perfectly for me using the sample code provided, however synchronous does not.
The sample code I am referring to is shown if you click on the link above. What I noticed is that it does not actually wait until the results are available. If I insert a time.sleep(15)
before the while True
, my results return as expected. If not, then the it returns an empty result set.
The official documentation example uses the query:
"""SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = @corpus
AND word_count >= @min_word_count
ORDER BY word_count DESC;
"""
This query returns very quickly, however my query takes several seconds to return a result.
My question is, why does the documentation state that the run_sync_query
command waits until the query completes, if the results are not actually accessible and no results are returned?
I cannot provide the query I used because it is a private data source. To produce, you just need a query that takes several seconds to run.
Upvotes: 3
Views: 2071
Reputation: 14791
Looks like the request/call is timing out, not the query itself. The default time is 10s. Try setting timeout_ms
in your code:
For example (I'm going to assume you are using Python):
..[auth/client setup stuff]..
query = client.run_sync_query('<your_query>')
query.timeout_ms = 60000 #set the request timeout
query.use_legacy_sql = False
query.use_query_cache = True
query.run()
..[do something with the results]..
Upvotes: 4