6.7. Users Billing Jobs to a Project

Below is an example of a query that can be used to analyze users that execute jobs billed to a given project.

The common table expression jobs_agg can be modified as needed. Choose an appropriate source view: JOBS_BY_PROJECT, JOBS_BY_ORGANIZATION, or an archive of one of these. Modify the filters as needed.

with
jobs_agg as
(
    select
        j.job_type
        ,j.user_email
        ,min(j.creation_time) as min_creation_time
        ,max(j.creation_time) as max_creation_time
        ,count(*) as job_count
        ,sum(j.total_slot_ms) as total_slot_ms
--     from `PROJECT_ID.region-us.INFORMATION_SCHEMA.JOBS_BY_ORGANIZATION` j
--     from `PROJECT_ID.region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT` j
    -- default to this query's billing project
    from `region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT` j
    where
        -- JOBS_BY_ tables partitioned on creation_time by day;
        -- creation_time is UTC and current_date defaults to UTC
        date(j.creation_time) between 
            date_add(
                current_date
                ,interval -30 day
            )
            and current_date
    group by
        j.job_type
        ,j.user_email
)
select
    j.job_type
    ,j.user_email
    ,format_timestamp(
        '%Y-%m-%d %H:%M:%E*S'
        ,j.min_creation_time
    ) as min_creation_time
    ,format_timestamp(
        '%Y-%m-%d %H:%M:%E*S'
        ,j.max_creation_time
    ) as max_creation_time
    ,j.job_count
    ,cast(j.job_count as float64)
        / sum(j.job_count) over (
            partition by
                j.job_type
        )
        as job_count_pct
    ,coalesce(
        j.total_slot_ms
        ,0
    ) as total_slot_ms
    ,cast(j.total_slot_ms as float64)
        / sum(j.total_slot_ms) over (
            partition by
                j.job_type
        )
        as total_slot_ms_pct
from jobs_agg j
order by
    j.job_type
    ,j.total_slot_ms desc
    ,j.job_count desc
    ,j.user_email
;