通过 bigquery 命令行工具在 BigQuery 中缓存

use*_*672 3 caching google-bigquery

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

Jor*_*ani 5

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

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

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

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

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

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

该查询结果应该是从缓存中获取的。这将在作业资源的 stats.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",
  },
}
Run Code Online (Sandbox Code Playgroud)