-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathintegrity__video_report.sql
53 lines (48 loc) · 1.53 KB
/
integrity__video_report.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
{{ config(
tags="fivetran_validations",
enabled=var('fivetran_validation_tests_enabled', false)
) }}
with staging as (
select
video_id,
source_relation,
sum(comments) as comments,
sum(dislikes) as dislikes,
sum(likes) as likes,
sum(shares) as shares,
sum(subscribers_gained) as subscribers_gained,
sum(subscribers_lost) as subscribers_lost,
sum(views) as views,
sum(watch_time_minutes) as watch_time_minutes
from {{ ref('stg_youtube__channel_basic') }}
group by 1, 2
),
report as (
select
video_id,
source_relation,
sum(comments) as comments,
sum(dislikes) as dislikes,
sum(likes) as likes,
sum(shares) as shares,
sum(subscribers_gained) as subscribers_gained,
sum(subscribers_lost) as subscribers_lost,
sum(views) as views,
sum(watch_time_minutes) as watch_time_minutes
from {{ ref('youtube__video_report') }}
group by 1, 2
)
select *
from staging
full outer join report
on staging.video_id = report.video_id
and staging.source_relation = report.source_relation
where
staging.comments != report.comments
and staging.dislikes != report.dislikes
and staging.likes != report.likes
and staging.shares != report.shares
and staging.subscribers_gained != report.subscribers_gained
and staging.subscribers_lost != report.subscribers_lost
and staging.views != report.views
and staging.watch_time_minutes != report.watch_time_minutes