forked from dbt-labs/dbt-project-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfct_test_coverage.sql
32 lines (26 loc) · 1.02 KB
/
fct_test_coverage.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
with
test_counts as (
select * from {{ ref('int_model_test_summary') }}
),
conversion as (
select
resource_name,
case when number_of_tests_on_model > 0 then 1 else 0 end as is_tested_model,
case when model_type = 'marts' then 1.0 else NULL end as is_marts_model,
case when number_of_tests_on_model > 0 and model_type = 'marts' then 1.0 else 0 end as is_tested_marts_model
from test_counts
),
final as (
select
current_timestamp as measured_at,
count(*) as total_models,
sum(number_of_tests_on_model) as total_tests,
sum(is_tested_model) as tested_models,
round(sum(is_tested_model) * 100.0 / count(*), 2) as test_coverage_pct,
round(sum(is_tested_marts_model) * 100.0 / count(is_marts_model), 2) as marts_test_coverage_pct,
round(sum(number_of_tests_on_model) * 1.0 / count(*), 4) as test_to_model_ratio
from test_counts
left join conversion
on test_counts.resource_name = conversion.resource_name
)
select * from final