Skip to content

Commit c350293

Browse files
authored
Merge pull request #390 from poloaraujo/pa/format-consistency
Format all models for consistency
2 parents 3afcfbd + 7b4378a commit c350293

35 files changed

+846
-785
lines changed

models/dim_dbt__current_models.sql

Lines changed: 106 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,108 @@
1-
with base as (
2-
select *
3-
from {{ ref('stg_dbt__models') }}
4-
),
5-
6-
model_executions as (
7-
select *
8-
from {{ ref('stg_dbt__model_executions') }}
9-
),
10-
11-
latest_models as (
12-
/* Retrieves the models present in the most recent run */
13-
select *
14-
from base
15-
where run_started_at = (select max(run_started_at) from base)
16-
),
17-
18-
latest_models_runs as (
19-
/* Retreives all successful run information for the models present in the most
20-
recent run and ranks them based on query completion time */
21-
select
22-
model_executions.node_id
23-
, model_executions.was_full_refresh
24-
, model_executions.query_completed_at
25-
, model_executions.total_node_runtime
26-
, model_executions.rows_affected
27-
{% if target.type == 'bigquery' %}
28-
, model_executions.bytes_processed
29-
{% endif %}
30-
/* Row number by refresh and node ID */
31-
, row_number() over (
32-
partition by latest_models.node_id, model_executions.was_full_refresh
33-
order by model_executions.query_completed_at desc /* most recent ranked first */
34-
) as run_idx
35-
/* Row number by node ID */
36-
, row_number() over (
37-
partition by latest_models.node_id
38-
order by model_executions.query_completed_at desc /* most recent ranked first */
39-
) as run_idx_id_only
40-
from model_executions
41-
inner join latest_models on model_executions.node_id = latest_models.node_id
42-
where model_executions.status = 'success'
43-
),
44-
45-
latest_model_stats as (
46-
select
47-
node_id
48-
, max(case when was_full_refresh then query_completed_at end) as last_full_refresh_run_completed_at
49-
, max(case when was_full_refresh then total_node_runtime end) as last_full_refresh_run_total_runtime
50-
, max(case when was_full_refresh then rows_affected end) as last_full_refresh_run_rows_affected
51-
{% if target.type == 'bigquery' %}
52-
, max(case when was_full_refresh then bytes_processed end) as last_full_refresh_run_bytes_processed
53-
{% endif %}
54-
, max(case when run_idx_id_only = 1 then query_completed_at end) as last_run_completed_at
55-
, max(case when run_idx_id_only = 1 then total_node_runtime end) as last_run_total_runtime
56-
, max(case when run_idx_id_only = 1 then rows_affected end) as last_run_rows_affected
57-
{% if target.type == 'bigquery' %}
58-
, max(case when run_idx_id_only = 1 then bytes_processed end) as last_run_bytes_processed
59-
{% endif %}
60-
, max(case when not was_full_refresh then query_completed_at end) as last_incremental_run_completed_at
61-
, max(case when not was_full_refresh then total_node_runtime end) as last_incremental_run_total_runtime
62-
, max(case when not was_full_refresh then rows_affected end) as last_incremental_run_rows_affected
63-
{% if target.type == 'bigquery' %}
64-
, max(case when not was_full_refresh then bytes_processed end) as last_incremental_run_bytes_processed
65-
{% endif %}
66-
from latest_models_runs
67-
where run_idx = 1
68-
group by 1
69-
),
70-
71-
final as (
72-
select
73-
latest_models.*
74-
, latest_model_stats.last_full_refresh_run_completed_at
75-
, latest_model_stats.last_full_refresh_run_total_runtime
76-
, latest_model_stats.last_full_refresh_run_rows_affected
77-
{% if target.type == 'bigquery' %}
78-
, latest_model_stats.last_full_refresh_run_bytes_processed
79-
{% endif %}
80-
, latest_model_stats.last_run_completed_at
81-
, latest_model_stats.last_run_total_runtime
82-
, latest_model_stats.last_run_rows_affected
83-
{% if target.type == 'bigquery' %}
84-
, latest_model_stats.last_run_bytes_processed
85-
{% endif %}
86-
, latest_model_stats.last_incremental_run_completed_at
87-
, latest_model_stats.last_incremental_run_total_runtime
88-
, latest_model_stats.last_incremental_run_rows_affected
89-
{% if target.type == 'bigquery' %}
90-
, latest_model_stats.last_incremental_run_bytes_processed
91-
{% endif %}
92-
from latest_models
93-
left join latest_model_stats
94-
on latest_models.node_id = latest_model_stats.node_id
95-
)
1+
with
2+
base as (
3+
4+
select * from {{ ref('stg_dbt__models') }}
5+
6+
)
7+
8+
, model_executions as (
9+
10+
select * from {{ ref('stg_dbt__model_executions') }}
11+
12+
)
13+
14+
, latest_models as (
15+
16+
/* Retrieves the models present in the most recent run */
17+
select *
18+
from base
19+
where run_started_at = (select max(run_started_at) from base)
20+
21+
)
22+
23+
, latest_models_runs as (
24+
25+
/* Retreives all successful run information for the models present in the most
26+
recent run and ranks them based on query completion time */
27+
select
28+
model_executions.node_id
29+
, model_executions.was_full_refresh
30+
, model_executions.query_completed_at
31+
, model_executions.total_node_runtime
32+
, model_executions.rows_affected
33+
{% if target.type == 'bigquery' %}
34+
, model_executions.bytes_processed
35+
{% endif %}
36+
/* Row number by refresh and node ID */
37+
, row_number() over (
38+
partition by latest_models.node_id, model_executions.was_full_refresh
39+
order by model_executions.query_completed_at desc /* most recent ranked first */
40+
) as run_idx
41+
/* Row number by node ID */
42+
, row_number() over (
43+
partition by latest_models.node_id
44+
order by model_executions.query_completed_at desc /* most recent ranked first */
45+
) as run_idx_id_only
46+
from model_executions
47+
inner join latest_models on model_executions.node_id = latest_models.node_id
48+
where model_executions.status = 'success'
49+
50+
)
51+
52+
, latest_model_stats as (
53+
54+
select
55+
node_id
56+
, max(case when was_full_refresh then query_completed_at end) as last_full_refresh_run_completed_at
57+
, max(case when was_full_refresh then total_node_runtime end) as last_full_refresh_run_total_runtime
58+
, max(case when was_full_refresh then rows_affected end) as last_full_refresh_run_rows_affected
59+
{% if target.type == 'bigquery' %}
60+
, max(case when was_full_refresh then bytes_processed end) as last_full_refresh_run_bytes_processed
61+
{% endif %}
62+
, max(case when run_idx_id_only = 1 then query_completed_at end) as last_run_completed_at
63+
, max(case when run_idx_id_only = 1 then total_node_runtime end) as last_run_total_runtime
64+
, max(case when run_idx_id_only = 1 then rows_affected end) as last_run_rows_affected
65+
{% if target.type == 'bigquery' %}
66+
, max(case when run_idx_id_only = 1 then bytes_processed end) as last_run_bytes_processed
67+
{% endif %}
68+
, max(case when not was_full_refresh then query_completed_at end) as last_incremental_run_completed_at
69+
, max(case when not was_full_refresh then total_node_runtime end) as last_incremental_run_total_runtime
70+
, max(case when not was_full_refresh then rows_affected end) as last_incremental_run_rows_affected
71+
{% if target.type == 'bigquery' %}
72+
, max(case when not was_full_refresh then bytes_processed end) as last_incremental_run_bytes_processed
73+
{% endif %}
74+
from latest_models_runs
75+
where run_idx = 1
76+
group by 1
77+
78+
)
79+
80+
, final as (
81+
82+
select
83+
latest_models.*
84+
, latest_model_stats.last_full_refresh_run_completed_at
85+
, latest_model_stats.last_full_refresh_run_total_runtime
86+
, latest_model_stats.last_full_refresh_run_rows_affected
87+
{% if target.type == 'bigquery' %}
88+
, latest_model_stats.last_full_refresh_run_bytes_processed
89+
{% endif %}
90+
, latest_model_stats.last_run_completed_at
91+
, latest_model_stats.last_run_total_runtime
92+
, latest_model_stats.last_run_rows_affected
93+
{% if target.type == 'bigquery' %}
94+
, latest_model_stats.last_run_bytes_processed
95+
{% endif %}
96+
, latest_model_stats.last_incremental_run_completed_at
97+
, latest_model_stats.last_incremental_run_total_runtime
98+
, latest_model_stats.last_incremental_run_rows_affected
99+
{% if target.type == 'bigquery' %}
100+
, latest_model_stats.last_incremental_run_bytes_processed
101+
{% endif %}
102+
from latest_models
103+
left join latest_model_stats
104+
on latest_models.node_id = latest_model_stats.node_id
105+
106+
)
96107

97108
select * from final

models/dim_dbt__exposures.sql

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
with base as (
1+
with
2+
base as (
23

3-
select *
4-
from {{ ref('stg_dbt__exposures') }}
4+
select *
5+
from {{ ref('stg_dbt__exposures') }}
56

6-
),
7+
)
78

8-
exposures as (
9+
, exposures as (
910

10-
select
11-
exposure_execution_id,
12-
command_invocation_id,
13-
node_id,
14-
run_started_at,
15-
name,
16-
type,
17-
owner,
18-
maturity,
19-
path,
20-
description,
21-
url,
22-
package_name,
23-
depends_on_nodes,
24-
tags
25-
from base
11+
select
12+
exposure_execution_id
13+
, command_invocation_id
14+
, node_id
15+
, run_started_at
16+
, name
17+
, type
18+
, owner
19+
, maturity
20+
, path
21+
, description
22+
, url
23+
, package_name
24+
, depends_on_nodes
25+
, tags
26+
from base
2627

27-
)
28+
)
2829

2930
select * from exposures

models/dim_dbt__models.sql

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
with base as (
1+
with
2+
base as (
23

3-
select *
4-
from {{ ref('stg_dbt__models') }}
4+
select *
5+
from {{ ref('stg_dbt__models') }}
56

6-
),
7+
)
78

8-
models as (
9+
, models as (
910

10-
select
11-
model_execution_id,
12-
command_invocation_id,
13-
node_id,
14-
run_started_at,
15-
database,
16-
schema,
17-
name,
18-
depends_on_nodes,
19-
package_name,
20-
path,
21-
checksum,
22-
materialization,
23-
tags,
24-
meta,
25-
alias
26-
from base
11+
select
12+
model_execution_id
13+
, command_invocation_id
14+
, node_id
15+
, run_started_at
16+
, database
17+
, schema
18+
, name
19+
, depends_on_nodes
20+
, package_name
21+
, path
22+
, checksum
23+
, materialization
24+
, tags
25+
, meta
26+
, alias
27+
from base
2728

28-
)
29+
)
2930

3031
select * from models

models/dim_dbt__seeds.sql

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
with base as (
1+
with
2+
base as (
23

3-
select *
4-
from {{ ref('stg_dbt__seeds') }}
4+
select *
5+
from {{ ref('stg_dbt__seeds') }}
56

6-
),
7+
)
78

8-
seeds as (
9+
, seeds as (
910

10-
select
11-
seed_execution_id,
12-
command_invocation_id,
13-
node_id,
14-
run_started_at,
15-
database,
16-
schema,
17-
name,
18-
package_name,
19-
path,
20-
checksum,
21-
meta,
22-
alias
23-
from base
11+
select
12+
seed_execution_id
13+
, command_invocation_id
14+
, node_id
15+
, run_started_at
16+
, database
17+
, schema
18+
, name
19+
, package_name
20+
, path
21+
, checksum
22+
, meta
23+
, alias
24+
from base
2425

25-
)
26+
)
2627

2728
select * from seeds

0 commit comments

Comments
 (0)