从 bigquery 命令行工具缓存在 BigQuery 中



我正在使用bigquery命令行工具。如何通过 BigQuery 命令行工具启用缓存。

查询会自动缓存,但以下情况除外:

  • 使用非确定性函数(如 now() 或 rand())的查询不会被缓存。
  • 不会缓存指定目标表的查询(如果在目标表中获得了结果,则不需要缓存)。
  • 当任何源表发生更改时,将刷新缓存的结果。
  • 结果仅缓存 24 小时。

您可以通过从查询中查找作业对象来查看这一点。例如:

$ bq query select 17
Waiting on bqjob_r4c80a6944b4dff0_0000014165a4f730_1 ... (0s) Current status: DONE
+-----+
| f0_ |
+-----+
|  17 |
+-----+

这实际上运行了查询并将其添加到缓存中。现在让我们再次运行它:

$ bq query select 17
Waiting on bqjob_r27fa3d897b8dfb3e_0000014165a66b50_1 ... (0s) Current status: DONE
+-----+
| f0_ |
+-----+
|  17 |
+-----+

该查询结果应已从缓存中获取。这将在作业资源上的 statistics.query.cacheHit 成员中可见。让我们检查一下:

$ bq --format=prettyjson show -j bqjob_r27fa3d897b8dfb3e_0000014165a66b50_1
{
  "configuration": {
    "query": {
      ...
      "query": "select 17",
    }
  },
  ...
  "statistics": {
    "creationTime": "1380389907722",
    "endTime": "1380389908018",
    "query": {
      "cacheHit": true,
      "totalBytesProcessed": "0"
    },
    "startTime": "1380389907853",
  },
}

如 https://cloud.google.com/bigquery/docs/cached-results 中所述:

  • 默认情况下启用缓存
  • 它对新查询没有影响
  • 您可以使用 --nouse_cache 标志从命令行禁用缓存

默认情况下启用缓存,我们不需要从我们这边提供任何特定设置。它仅启用 24 小时。

最新更新