-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlinkedin_pages__posts.sql
85 lines (64 loc) · 2.33 KB
/
linkedin_pages__posts.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
with share_statistic as (
select *
from {{ var('share_statistic_staging') }}
),
ugc_post_share_statistic as (
select *
from {{ ref('int_linkedin_pages__latest_post') }}
where is_most_recent_record = true
),
ugc_post_history as (
select *
from {{ ref('int_linkedin_pages__latest_post_history') }}
where is_most_recent_record = true
),
post_content as (
select *
from {{ var('post_content') }}
),
organization as (
select *
from {{ var('organization_staging') }}
),
organization_ugc_post as (
select *
from {{ var('organization_ugc_post_staging') }}
),
joined as (
select
ugc_post_history.ugc_post_id,
ugc_post_history.post_author,
ugc_post_history.post_url,
ugc_post_history.created_timestamp,
ugc_post_history.first_published_timestamp,
ugc_post_history.lifecycle_state,
ugc_post_history.commentary,
organization.organization_id,
coalesce(post_content.article_title, post_content.media_title) as post_title,
post_content.post_type,
organization.organization_name,
share_statistic.click_count,
share_statistic.comment_count,
share_statistic.impression_count,
share_statistic.like_count,
share_statistic.share_count,
ugc_post_history.source_relation
from ugc_post_history
left join ugc_post_share_statistic
on ugc_post_share_statistic.ugc_post_id = ugc_post_history.ugc_post_id
and ugc_post_share_statistic.source_relation = ugc_post_history.source_relation
left join share_statistic
on share_statistic.share_statistic_id = ugc_post_share_statistic.share_statistic_id
and share_statistic.source_relation = ugc_post_share_statistic.source_relation
left join post_content
on ugc_post_history.ugc_post_urn = post_content.ugc_post_urn
and ugc_post_history.source_relation = post_content.source_relation
left join organization_ugc_post
on ugc_post_history.ugc_post_id = organization_ugc_post.ugc_post_id
and ugc_post_history.source_relation = organization_ugc_post.source_relation
left join organization
on organization_ugc_post.organization_id = organization.organization_id
and organization_ugc_post.source_relation = organization.source_relation
)
select *
from joined