BigQuery 同步查询未返回任何结果 [英] BigQuery synchronous query is not returning any results

查看:20
本文介绍了BigQuery 同步查询未返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据

例如(我假设您使用的是 Python):

..[身份验证/客户端设置内容]..query = client.run_sync_query('<your_query>')query.timeout_ms = 60000 #设置请求超时query.use_legacy_sql = Falsequery.use_query_cache = True查询运行()..[对结果做点什么]..

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.

解决方案

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]..

这篇关于BigQuery 同步查询未返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆