-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_group_by_domain_hour.sql
50 lines (39 loc) · 1.25 KB
/
test_group_by_domain_hour.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
with __dbt__cte__fact_emails as (
-- Fixture for fact_emails
select cast(null as integer) as email_id, cast(null as text) as object,
cast('toto@ippon.fr' as text)
as sender_address,
cast('2021-01-01 00:00:00' as timestamp without time zone)
as received_at
union all
select cast(null as integer) as email_id, cast(null as text) as object,
cast('titi@ippon.fr' as text)
as sender_address,
cast('2021-01-01 00:30:00' as timestamp without time zone)
as received_at
union all
select cast(null as integer) as email_id, cast(null as text) as object,
cast('tata@google.com' as text)
as sender_address,
cast('2021-01-01 00:00:00' as timestamp without time zone)
as received_at
union all
select cast(null as integer) as email_id, cast(null as text) as object,
cast('tata@google.com' as text)
as sender_address,
cast('2021-01-01 01:00:00' as timestamp without time zone)
as received_at
), emails as (
select * from __dbt__cte__fact_emails
)
, count_emails as (
select
date_trunc('hour', received_at) as sent_at_hour
, substring(sender_address from '@(.*)') as domain
, count(*) as email_count
from
emails
group by
1, 2
)
select * from count_emails