John McCrary
01/04/2024, 7:53 PMedrSamuel Garfield
01/05/2024, 9:16 PMwith per_test_summary as (
select
etr.table_name,
etr.column_name,
etr.test_name,
case job_id
when <insert here> then '<job name here>'
when <insert here> then '<job name here>'
else 'unknown' end as job_name,
sum(case when etr.status = 'warn' then 1 else 0 end) as num_warnings,
count(1) as num_runs
from database.elementary_schema.elementary_test_results etr
inner join (
select distinct invocation_id, job_id
from database.elementary_schema.dbt_invocations
where job_id in (
<insert job IDs>
)
and invocation_id is not null
-- Only invocations from last x complete days
and run_started_at >= date(from_utc_timestamp(current_timestamp, 'America/Los_Angeles')) - ({{ days_back }})
and run_started_at <= date(from_utc_timestamp(current_timestamp, 'America/Los_Angeles'))
) i on etr.invocation_id = i.invocation_id
group by 1,2,3,4
)
select
*,
num_warnings / num_runs as pct_of_time_warns
from per_test_summary
where num_warnings / num_runs >= {{ min pct time warning fired }}
order by 7 desc