确定 运行 BigQuery 作业之前的资源使用情况

Determine the resource usage before running BigQuery job

我已成功将 Big Query 与 Google 表格集成。
由于我使用动态参数来决定查询的性质(例如,时间范围),我想了解查询的 "cost" - 需要多少 MB(或 KB 或 GB) 运行.

之前 运行查询之前,有什么方法可以指示这种指示吗?

是的,您可以使用 dryRun 标志。服务器会告诉你它将处理的数量

{
  "configuration": {
    "query": {
      "query": "SELECT SUM(a.field) FROM `project.dataset.table`",
      "useLegacySql": false
    },
    "dryRun": true
  }
}

您需要评估提供的统计信息:

...
 "statistics": {
 "creationTime": "1526584760494",
  "totalBytesProcessed": "152193056",
  "query": {
   "totalBytesProcessed": "152193056",
   "totalBytesBilled": "0",
   "cacheHit": false,
...

如您所见,未对任何字节计费。 您可以在实施之前在这里尝试一下: https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert

没有真正的电子表格细节,因为 AppsScript 也使用 API。