-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da09991
commit 9d73802
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
with base as ( | ||
|
||
select * | ||
from {{ ref('stg_dbt__artifacts') }} | ||
|
||
), | ||
|
||
run_results as ( | ||
|
||
select * | ||
from base | ||
where artifact_type = 'run_results.json' | ||
|
||
), | ||
|
||
dbt_run as ( | ||
|
||
select * | ||
from run_results | ||
where data:args:which = 'test' | ||
|
||
), | ||
|
||
fields as ( | ||
|
||
select | ||
data:metadata:invocation_id::string as command_invocation_id, | ||
generated_at as artifact_generated_at, | ||
coalesce(data:args:full_refresh, 'false')::boolean as was_full_refresh, | ||
result.value:unique_id::string as node_id, | ||
split(result.value:thread_id::string, '-')[1]::integer as thread_id, | ||
result.value:status::string as status, | ||
result.value:message::string as message, | ||
|
||
-- The first item in the timing array is the model-level `compile` | ||
result.value:timing[0]:started_at::timestamp_ntz as compile_started_at, | ||
|
||
-- The second item in the timing array is `execute`. | ||
result.value:timing[1]:completed_at::timestamp_ntz as query_completed_at, | ||
|
||
-- Confusingly, this does not match the delta of the above two timestamps. | ||
-- should we calculate it instead? | ||
coalesce(result.value:execution_time::float, 0) as total_node_runtime, | ||
|
||
result.value:adapter_response:rows_affected::int as rows_affected | ||
from dbt_run, | ||
lateral flatten(input => data:results) as result | ||
|
||
), | ||
|
||
surrogate_key as ( | ||
|
||
select | ||
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id, | ||
command_invocation_id, | ||
artifact_generated_at, | ||
was_full_refresh, | ||
node_id, | ||
thread_id, | ||
status, | ||
message, | ||
compile_started_at, | ||
query_completed_at, | ||
total_node_runtime, | ||
rows_affected | ||
from fields | ||
|
||
) | ||
|
||
select * from surrogate_key |