如何在 App Engine 中最好地处理写入中间 table 的大型查询结果

How to best process large query results written to intermediate table in App Engine

我们是 运行 大型查询作业,我们达到了 128M 的响应大小并且 BigQuery 引发了 "Response too large to return. Consider setting allowLargeResults to true in your job configuration" 错误。

我们选择 allowLargeResults 方法来保持已经很复杂的 SQL 不变(而不是在此级别分块)。问题是处理写入中间结果的最佳方法是什么 table:

有这方面的经验和/或建议吗?

请注意,我们在 Google App Engine (Python)运行

谢谢!

不清楚"chunk processing"的具体原因是什么。如果您有一些 complex SQL 逻辑需要针对您的数据进行 运行 并且结果恰好大于当前的 128MB 限制 - 仍然使用 allowLargeResults 进行操作,而不是按照您需要的方式使用结果. 当然,你很可能有分块的原因,但它不被理解,因此使回答有问题
另一个建议是不要在一个问题中问很多问题——这会使回答变得非常有问题,所以你很有可能得不到回答

Finally, my answer for the only question that is relatively clear (for me at least)

The question here is what is the best way to chunk the rows (is there an efficient way to do this, e.g. is there an internal row number we can refer to?). We probably end up scanning the entire table for each chunk so this seems more costly than the export to GCS option

这取决于您的 table 是如何以及何时创建的!
如果您的 table 被加载为一个大负载 - 我看不出避免 table 一次又一次扫描的方法。
如果 table 是增量加载的并且最近 - 你有机会享受所谓的 Table Decoration (具体你应该看看 Range Decorators)

在 BigQuery 的早期时代,人们期望拥有分区装饰器——这将满足很多用户的需求——但它仍然不可用,我不知道他们有什么计划

请注意,BigQuery 能够以块的形式导出数据 - 您可以请求与您拥有的工作人员一样多的块。

来自https://cloud.google.com/bigquery/exporting-data-from-bigquery#exportingmultiple

如果您要求导出到:

['gs://my-bucket/file-name.json']

您将导出一个 GCS 文件,只要它小于 1GB。

如果您要求导出到:

['gs://my-bucket/file-name-*.json']

您将获得多个文件,每个文件都占总导出量的一部分。导出超过 1GB 时很有用。

如果您要求导出到:

['gs://my-bucket/file-name-1-*.json',
'gs://my-bucket/file-name-2-*.json',
'gs://my-bucket/file-name-3-*.json']

您将获得针对 3 名工人优化的出口。这些模式中的每一个都会收到一系列导出的块,因此每个工作人员都可以专注于自己的块。

我知道 https://cloud.google.com/bigquery/docs/reference/v2/tabledata/list 可以让您在不执行查询的情况下读取 table 的块(产生数据处理费用)。

这让您可以并行读取查询结果,所有查询都写入临时 table id,您可以将其传递给此函数并提供不同的范围(使用 startIndex、maxResults)。