Last active
June 24, 2024 11:20
-
-
Save Wintus/4b766c953663ef291ffd221a620efafc to your computer and use it in GitHub Desktop.
Google Cloud: GIG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW bq_logs.v_querylogs AS | |
WITH job_completed_event AS ( | |
SELECT | |
resource.labels.project_id, | |
protopayload_auditlog.authenticationInfo.principalEmail, | |
protopayload_auditlog.servicedata_v1_bigquery.jobCompletedEvent.job AS job, | |
severity | |
FROM `bq_logs.cloudaudit_googleapis_com_data_access_*` | |
) | |
SELECT | |
project_id, | |
principalEmail, | |
job.jobConfiguration.query.query, | |
job.jobConfiguration.query.statementType, | |
job.jobStatus.error.message, | |
job.jobStatistics.startTime, | |
job.jobStatistics.endTime, | |
TIMESTAMP_DIFF(job.jobStatistics.endTime, job.jobStatistics.startTime, MILLISECOND)/1000 AS run_seconds, | |
job.jobStatistics.totalProcessedBytes, | |
job.jobStatistics.totalSlotMs, | |
ARRAY_TO_STRING(ARRAY( | |
SELECT CONCAT(datasetid, '.', tableId) | |
FROM UNNEST(job.jobStatistics.referencedTables) | |
), ',') AS tables_ref, | |
job.jobStatistics.totalTablesProcessed, | |
job.jobStatistics.queryOutputRowCount, | |
severity | |
FROM job_completed_event | |
ORDER BY job.jobStatistics.startTime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref.