Skip to content

Commit 413068e

Browse files
authored
Merge pull request #4 from tailsdotcom/build_speed
Improve build speed and add dim_dbt__models
2 parents 834074a + 9de6729 commit 413068e

File tree

5 files changed

+110
-4
lines changed

5 files changed

+110
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ This package builds a mart of tables from dbt artifacts loaded into a table. It
33

44
Models included:
55

6-
- `fct_dbt_model_executions`
7-
- `fct_dbt_run_results`
6+
- `dim_dbt__models`
7+
- `fct_dbt__model_executions`
88
- `fct_dbt__latest_full_model_executions`
99
- `fct_dbt__critical_path`
10+
- `fct_dbt_run_results`
1011

1112
The critical path model determines the slowest route through your DAG, which provides you with the information needed to make a targeted effort to reducing `dbt run` times. For example:
1213

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{ config( materialized='incremental', unique_key='manifest_model_id' ) }}
2+
3+
with dbt_models as (
4+
5+
select * from {{ ref('stg_dbt__models') }}
6+
7+
),
8+
9+
dbt_models_incremental as (
10+
11+
select *
12+
from dbt_models
13+
14+
{% if is_incremental() %}
15+
-- this filter will only be applied on an incremental run
16+
where artifact_generated_at > (select max(artifact_generated_at) from {{ this }})
17+
{% endif %}
18+
19+
),
20+
21+
fields as (
22+
23+
select
24+
manifest_model_id,
25+
command_invocation_id,
26+
artifact_generated_at,
27+
node_id,
28+
name,
29+
model_schema,
30+
depends_on_nodes,
31+
package_name,
32+
model_path,
33+
checksum,
34+
model_materialization
35+
from dbt_models_incremental
36+
37+
)
38+
39+
select * from fields

models/incremental/fct_dbt__model_executions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
with models as (
44

55
select *
6-
from {{ ref('stg_dbt__models') }}
6+
from {{ ref('dim_dbt__models') }}
77

88
),
99

1010
model_executions as (
1111

1212
select *
13-
from {{ ref('stg_dbt__model_executions') }}
13+
from {{ ref('int_dbt__model_executions') }}
1414

1515
),
1616

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{ config( materialized='incremental', unique_key='model_execution_id' ) }}
2+
3+
with model_executions as (
4+
5+
select *
6+
from {{ ref('stg_dbt__model_executions') }}
7+
8+
),
9+
10+
model_executions_incremental as (
11+
12+
select *
13+
from model_executions
14+
15+
{% if is_incremental() %}
16+
-- this filter will only be applied on an incremental run
17+
where artifact_generated_at > (select max(artifact_generated_at) from {{ this }})
18+
{% endif %}
19+
20+
),
21+
22+
fields as (
23+
24+
select
25+
model_execution_id,
26+
command_invocation_id,
27+
artifact_generated_at,
28+
was_full_refresh,
29+
node_id,
30+
thread_id,
31+
status,
32+
compile_started_at,
33+
query_completed_at,
34+
total_node_runtime,
35+
rows_affected
36+
from model_executions_incremental
37+
38+
)
39+
40+
select * from fields

models/schemas.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,29 @@ models:
103103
description: Was the run executed with a --full-refresh flag?
104104
- name: env_*
105105
description: Columns for the environment variables set when the command was executed.
106+
107+
- name: dim_dbt__models
108+
description: All dbt model metadata from every manifest.json.
109+
columns:
110+
- name: manifest_model_id
111+
description: Primary key generated from the command_invocation_id and checksum.
112+
tests:
113+
- unique
114+
- not_null
115+
- name: command_invocation_id
116+
description: The id of the command which resulted in the source artifact's generation.
117+
- name: artifact_generated_at
118+
description: Timestamp of when the source artifact was generated.
119+
- name: node_id
120+
description: Unique id for the node, in the form of model.[package_name].[model_name]
121+
- name: name
122+
description: The model name.
123+
- name: model_schema
124+
- name: depends_on_nodes
125+
description: List of node ids the model depends on.
126+
- name: package_name
127+
- name: model_path
128+
description: Filepath of the model.
129+
- name: checksum
130+
description: Unique identifier for the model. If a model is unchanged between separate executions this will remain the same.
131+
- name: model_materialization

0 commit comments

Comments
 (0)