Skip to content

Instantly share code, notes, and snippets.

@Wintus
Last active June 24, 2024 11:20
Show Gist options
  • Save Wintus/4b766c953663ef291ffd221a620efafc to your computer and use it in GitHub Desktop.
Save Wintus/4b766c953663ef291ffd221a620efafc to your computer and use it in GitHub Desktop.
Google Cloud: GIG
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;
@Wintus
Copy link
Author

Wintus commented Jun 23, 2024

ref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment