How to get table name when using TABLE_DATE_RANGE

后端 未结 1 1134
深忆病人
深忆病人 2021-02-10 20:41

I would like to get daily statistics using TABLE_DATE_RANGE like this:

Select count(*), tableName
FROM
(TABLE_DATE_RANGE(appengine_logs.appengine_googleapis_com_         


        
相关标签:
1条回答
  • 2021-02-10 21:08

    You need to query your dataset with a metadata query.

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

    this returns

    +-----+------------+------------+-----------------+---------------+--------------------+-----------+--------------+------+---+
    | 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 |   |
    +-----+------------+------------+-----------------+---------------+--------------------+-----------+--------------+------+---+
    

    You can add in the WHERE clauses to restrict to tables similar to

    • WHERE table_id contains "wiki"
    • or regexp like WHERE REGEXP_MATCH(table_id, r"^foo[\d]{3,5}")
    0 讨论(0)
提交回复
热议问题