BigQuery API PY 客户端库 - Client.query() 与 Client.query_rows() 之间的区别

BigQuery API PY Client Library - Difference between Client.query() vs Client.query_rows()

我正在学习使用 Google 用于 Python v0.28 - https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html#queries

的 BigQuery 客户端库来使用 BigQuery API

无法理解以下两种查询数据方式的区别

query(query, job_config=None, job_id=None, job_id_prefix=None, retry=<google.api_core.retry.Retry object>)
query_rows(query, job_config=None, job_id=None, job_id_prefix=None, timeout=None, retry=<google.api_core.retry.Retry object>)

这两者有何区别?在什么情况下您会优先使用其中一个?对我来说,两者似乎都是我们查询 table.

的一种方式

非常感谢您提供深入的见解!

干杯!

它们确实有点相同,但有一个主要区别:query_rows 可以被认为是同步实现,因为它将等待作业完成,而 return 对您来说是一个带有结果的迭代器。

运行 它将阻止您的 python 解释器,直到工作完成。

另一方面,

query 是异步的,如果您 运行 它,您的解释器将可以自由执行其他操作,而不管工作是否完成(由您决定等待工作并获得结果)。

正如您在 source code 中所见,query_rows 在其方法内调用 self.query,然后调用 result(等待作业完成)。