Skip to content

Commit 1338d9a

Browse files
kgpaynekon-mal
andauthored
Capturing exposures data (#18) (#21)
* Capturing exposures data (#18) * Added three models to capture exposures data: stg, dim and fct. * Refactored fct model to adhere to dbt style guide. * Fix indentation bug. * CI Build * CI Build * CI Build * Still fighting CI. * Verify dbt is running from the correct dir. Co-authored-by: Konrad <77880496+kon-mal@users.noreply.github.com>
1 parent 7623f43 commit 1338d9a

File tree

6 files changed

+158
-6
lines changed

6 files changed

+158
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
name: "Run Tests - Snowflake"
2929
command: |
3030
. venv/bin/activate
31-
echo `pwd`
3231
cd integration_tests
32+
echo `pwd`
3333
dbt --warn-error deps --target snowflake
3434
dbt --warn-error run-operation create_artifact_resources --target snowflake
3535
dbt --warn-error seed --target snowflake --full-refresh
@@ -43,7 +43,6 @@ jobs:
4343
dbt --warn-error docs generate --target snowflake
4444
dbt --warn-error run-operation upload_dbt_artifacts --args '{filenames: [catalog]}' --target snowflake
4545
46-
4746
- save_cache:
4847
key: deps1-{{ .Branch }}
4948
paths:

integration_tests/ci/sample.profiles.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ config:
66
send_anonymous_usage_stats: False
77
use_colors: True
88

9-
integration_tests:
9+
dbt_artifacts_integration_tests:
1010
target: snowflake
1111
outputs:
1212
snowflake:

integration_tests/dbt_project.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'artifacts_integration_tests'
22
version: '1.0'
33
config-version: 2
44

5-
profile: 'integration_tests'
5+
profile: 'dbt_artifacts_integration_tests'
66

77
source-paths: ["models"]
88
analysis-paths: ["analysis"]
@@ -12,8 +12,8 @@ macro-paths: ["macros"]
1212

1313
target-path: "target"
1414
clean-targets:
15-
- "target"
16-
- "dbt_modules"
15+
- "target"
16+
- "dbt_modules"
1717

1818
seeds:
1919
+quote_columns: false

models/fct_dbt__exposures_updates.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
with model_executions as (
2+
3+
select * from {{ ref('fct_dbt__model_executions') }}
4+
5+
),
6+
7+
exposures_record as (
8+
9+
select * from {{ ref('dim_dbt__exposures') }}
10+
11+
)
12+
13+
model_updates as (
14+
15+
select
16+
max(query_completed_at) as latest_update,
17+
node_id
18+
from model_executions
19+
group by node_id
20+
21+
),
22+
23+
exposures_latest as (
24+
25+
select
26+
artifact_generated_at as latest_generation,
27+
node_id,
28+
name,
29+
type,
30+
owner,
31+
maturity,
32+
package_name,
33+
output_feeds
34+
from exposures_record
35+
where artifact_generated_at = (select max(artifact_generated_at) from exposures_record)
36+
37+
),
38+
39+
exposures_updates as (
40+
41+
select
42+
e.latest_generation,
43+
e.node_id,
44+
e.name,
45+
e.type,
46+
e.owner,
47+
e.maturity,
48+
e.package_name,
49+
e.output_feeds,
50+
latest_update as feed_latest_update
51+
from exposures e
52+
left join model_updates m
53+
on m.node_id = e.output_feeds
54+
55+
)
56+
57+
select * from exposures_updates
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{
2+
config(
3+
materialized='incremental',
4+
unique_key='manifest_model_id'
5+
)
6+
}}
7+
8+
with dbt_models as (
9+
10+
select * from {{ ref('stg_dbt__exposures') }}
11+
12+
),
13+
14+
dbt_models_incremental as (
15+
16+
select *
17+
from dbt_models
18+
19+
{% if is_incremental() %}
20+
-- this filter will only be applied on an incremental run
21+
where artifact_generated_at > (select max(artifact_generated_at) from {{ this }})
22+
{% endif %}
23+
24+
),
25+
26+
fields as (
27+
28+
select
29+
t.manifest_model_id,
30+
t.command_invocation_id,
31+
t.artifact_generated_at,
32+
t.node_id,
33+
t.name,
34+
t.type,
35+
t.owner,
36+
t.maturity,
37+
f.value::string as output_feeds,
38+
t.package_name
39+
from dbt_models_incremental t,
40+
lateral flatten(input => depends_on_nodes) f
41+
42+
)
43+
44+
select * from fields

models/staging/stg_dbt__exposures.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
with base as (
2+
3+
select *
4+
from {{ ref('stg_dbt__artifacts') }}
5+
6+
),
7+
8+
manifests as (
9+
10+
select *
11+
from base
12+
where artifact_type = 'manifest.json'
13+
14+
),
15+
16+
flatten as (
17+
18+
select
19+
command_invocation_id,
20+
generated_at as artifact_generated_at,
21+
node.key as node_id,
22+
node.value:name::string as name,
23+
to_array(node.value:depends_on:nodes) as depends_on_nodes,
24+
to_array(node.value:sources:nodes) as depends_on_sources,
25+
node.value:type::string as type,
26+
node.value:owner:name::string as owner,
27+
node.value:maturity::string as maturity,
28+
node.value:package_name::string as package_name
29+
from manifests,
30+
lateral flatten(input => data:exposures) as node
31+
32+
),
33+
34+
surrogate_key as (
35+
36+
select
37+
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_model_id,
38+
command_invocation_id,
39+
artifact_generated_at,
40+
node_id,
41+
name,
42+
depends_on_nodes,
43+
depends_on_sources,
44+
type,
45+
owner,
46+
maturity,
47+
package_name
48+
from flatten
49+
50+
)
51+
52+
select * from surrogate_key

0 commit comments

Comments
 (0)