问题
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