Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get table name when using TABLE_DATE_RANGE

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_request_log_,
DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY'), CURRENT_TIMESTAMP()))
group by tableName

Is there any way to get a table name when using TABLE_DATE_RANGE?

like image 880
Ula Krukar Avatar asked Feb 11 '23 15:02

Ula Krukar


1 Answers

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}")
like image 129
Pentium10 Avatar answered Feb 13 '23 07:02

Pentium10