1+ -- add tag column
2+ ALTER TABLE umami .website_event ADD COLUMN " distinct_id" String AFTER " tag" ;
3+ ALTER TABLE umami .website_event_stats_hourly ADD COLUMN " distinct_id" String AFTER " tag" ;
4+ ALTER TABLE umami .session_data ADD COLUMN " distinct_id" String AFTER " data_type" ;
5+
6+ -- update materialized view
7+ DROP TABLE umami .website_event_stats_hourly_mv ;
8+
9+ CREATE MATERIALIZED VIEW umami .website_event_stats_hourly_mv
10+ TO umami .website_event_stats_hourly
11+ AS
12+ SELECT
13+ website_id,
14+ session_id,
15+ visit_id,
16+ hostname,
17+ browser,
18+ os,
19+ device,
20+ screen,
21+ language,
22+ country,
23+ region,
24+ city,
25+ entry_url,
26+ exit_url,
27+ url_paths as url_path,
28+ url_query,
29+ utm_source,
30+ utm_medium,
31+ utm_campaign,
32+ utm_content,
33+ utm_term,
34+ referrer_domain,
35+ page_title,
36+ gclid,
37+ fbclid,
38+ msclkid,
39+ ttclid,
40+ li_fat_id,
41+ twclid,
42+ event_type,
43+ event_name,
44+ views,
45+ min_time,
46+ max_time,
47+ tag,
48+ distinct_id,
49+ timestamp as created_at
50+ FROM (SELECT
51+ website_id,
52+ session_id,
53+ visit_id,
54+ hostname,
55+ browser,
56+ os,
57+ device,
58+ screen,
59+ language,
60+ country,
61+ region,
62+ city,
63+ argMinState(url_path, created_at) entry_url,
64+ argMaxState(url_path, created_at) exit_url,
65+ arrayFilter(x - > x != ' ' , groupArray(url_path)) as url_paths,
66+ arrayFilter(x - > x != ' ' , groupArray(url_query)) url_query,
67+ arrayFilter(x - > x != ' ' , groupArray(utm_source)) utm_source,
68+ arrayFilter(x - > x != ' ' , groupArray(utm_medium)) utm_medium,
69+ arrayFilter(x - > x != ' ' , groupArray(utm_campaign)) utm_campaign,
70+ arrayFilter(x - > x != ' ' , groupArray(utm_content)) utm_content,
71+ arrayFilter(x - > x != ' ' , groupArray(utm_term)) utm_term,
72+ arrayFilter(x - > x != ' ' , groupArray(referrer_domain)) referrer_domain,
73+ arrayFilter(x - > x != ' ' , groupArray(page_title)) page_title,
74+ arrayFilter(x - > x != ' ' , groupArray(gclid)) gclid,
75+ arrayFilter(x - > x != ' ' , groupArray(fbclid)) fbclid,
76+ arrayFilter(x - > x != ' ' , groupArray(msclkid)) msclkid,
77+ arrayFilter(x - > x != ' ' , groupArray(ttclid)) ttclid,
78+ arrayFilter(x - > x != ' ' , groupArray(li_fat_id)) li_fat_id,
79+ arrayFilter(x - > x != ' ' , groupArray(twclid)) twclid,
80+ event_type,
81+ if(event_type = 2 , groupArray(event_name), []) event_name,
82+ sumIf(1 , event_type = 1 ) views,
83+ min (created_at) min_time,
84+ max (created_at) max_time,
85+ arrayFilter(x - > x != ' ' , groupArray(tag)) tag,
86+ distinct_id,
87+ toStartOfHour(created_at) timestamp
88+ FROM umami .website_event
89+ GROUP BY website_id,
90+ session_id,
91+ visit_id,
92+ hostname,
93+ browser,
94+ os,
95+ device,
96+ screen,
97+ language,
98+ country,
99+ region,
100+ city,
101+ event_type,
102+ distinct_id,
103+ timestamp );
0 commit comments