如何在使用TABLE_DATE_RANGE时获取表名

时间:2015-03-18 13:49:56

标签: google-bigquery

我想使用TABLE_DATE_RANGE获取每日统计数据:

Select count(*), tableName
FROM
(TABLE_DATE_RANGE(appengine_logs.appengine_googleapis_com_request_log_,
DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY'), CURRENT_TIMESTAMP()))
group by tableName

使用TABLE_DATE_RANGE时有没有办法获取表名?

1 个答案:

答案 0 :(得分:8)

您需要使用元数据查询来查询数据集。

SELECT * FROM publicdata:samples.__TABLES__ 
WHERE MSEC_TO_TIMESTAMP(creation_time)  < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')

返回

+-----+------------+------------+-----------------+---------------+--------------------+-----------+--------------+------+---+
| Row | project_id | dataset_id |    table_id     | creation_time | last_modified_time | row_count |  size_bytes  | type |   |
+-----+------------+------------+-----------------+---------------+--------------------+-----------+--------------+------+---+
|   1 | publicdata | samples    | github_nested   | 1348782587310 |      1348782587310 |   2541639 |   1694950811 |    1 |   |
|   2 | publicdata | samples    | github_timeline | 1335915950690 |      1335915950690 |   6219749 |   3801936185 |    1 |   |
|   3 | publicdata | samples    | gsod            | 1335916040125 |      1413937987846 | 114420316 |  17290009238 |    1 |   |
|   4 | publicdata | samples    | natality        | 1335916045005 |      1413925598038 | 137826763 |  23562717384 |    1 |   |
|   5 | publicdata | samples    | shakespeare     | 1335916045099 |      1413926827257 |    164656 |      6432064 |    1 |   |
|   6 | publicdata | samples    | trigrams        | 1335916127449 |      1335916127449 |  68051509 | 277168458677 |    1 |   |
|   7 | publicdata | samples    | wikipedia       | 1335916132870 |      1423520879902 | 313797035 |  38324173849 |    1 |   |
+-----+------------+------------+-----------------+---------------+--------------------+-----------+--------------+------+---+

您可以添加WHERE子句以限制类似于

的表
  • WHERE table_id contains "wiki"
  • 或regexp,如WHERE REGEXP_MATCH(table_id, r"^foo[\d]{3,5}")