Get the Last Access date for all BigQuery tables in a BigQuery Project

纵然是瞬间 提交于 2020-01-21 15:59:49

问题


I know how to get the date a table was last modified, but not accessed. Is it possible to get the last time a table was read ? Is there query or an API to get this ?


回答1:


If you have audit logs in BigQuery, you can write a query like this:

WITH tables AS (
  SELECT FORMAT("%s.%s.%s", table.projectId, table.datasetId, table.tableId) table
    , MAX(timestamp) last_access
  FROM (
    SELECT timestamp
      , protopayload_auditlog.servicedata_v1_bigquery.jobCompletedEvent.job.jobStatistics.referencedTables  
    FROM `fh-bigquery.audit.cloudaudit_googleapis_com_data_access_201811*`
  ), UNNEST(referencedTables) table
  GROUP BY 1
)

SELECT * 
FROM tables



来源:https://stackoverflow.com/questions/53310574/get-the-last-access-date-for-all-bigquery-tables-in-a-bigquery-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!