Hi, I am trying to use the dbt_run_results table s...
# community-support
b
Hi, I am trying to use the dbt_run_results table so I can identify the tests that are taking a long time to run. I am only interested in tests in a particular schema - but I cannot find a good way to connect the dbt_run_results table with other elementary tables like dbt_models or elementary_test_results with the columns available in the dbt_run_results table. Any suggestions?
c
Hi Benjamin, You could join on the columns
dbt_run_results.model_execution_id = elementary_test_results.test_execution_id
. For example the query below would rank the tests in the schema
<SCHEMA_OF_INTEREST>
by decreasing execution time. Hope this helps.
Copy code
with _execution_time as (
    select 
        model_execution_id,
        unique_id,
        execution_time
    from dbt_run_results
),
_test_results as (
    select
        test_execution_id,
        test_unique_id,
        schema_name
    from elementary_test_results
    where schema_name = '<SCHEMA_OF_INTEREST>'
)
select
    test_unique_id,
    max(execution_time) as max_execution_time
from _test_results
left join _execution_time on model_execution_id=test_execution_id
group by test_unique_id
order by max_execution_time desc;
b
thank you, I think this works!