1+ CREATE TEMPORARY VIEW temp_view AS
2+ select
3+ e.application_id as id,
4+ e.main_id as main_id,
5+ (
6+ case
7+ when r.province = 'Hongkong' then '22.27747'
8+ WHEN r.province = 'Macao' then '22.16252'
9+ WHEN r.province = 'Taiwan' then '25.04573'
10+ ELSE m.lat
11+ END
12+ ) as lat,
13+ (
14+ case
15+ when r.province = 'Hongkong' then '114.1712'
16+ WHEN r.province = 'Macao' then '113.5838'
17+ WHEN r.province = 'Taiwan' then '121.5117'
18+ ELSE m.lng
19+ END
20+ ) as lng,
21+ (
22+ case
23+ when r.province = 'Hongkong' then 'HK'
24+ WHEN r.province = 'Macao' then 'MO'
25+ WHEN r.province = 'Taiwan' then 'TW'
26+ ELSE r.areacode
27+ END
28+ ) as region,
29+ count(distinct e.s_id) filter (
30+ where
31+ TIMESTAMPDIFF(MINUTE, e.rowtime, LOCALTIMESTAMP) <= 10
32+ ) as uv,
33+ count(e.s_id) filter (
34+ where
35+ TIMESTAMPDIFF(MINUTE, e.rowtime, LOCALTIMESTAMP) <= 10
36+ ) as pv,
37+ HOP_END(e.proctime, INTERVAL '10' SECOND, INTERVAL '10' MINUTE) as dt
38+ from
39+ filter_uv e
40+ left join lookup_ip_info FOR SYSTEM_TIME AS OF e.proctime as r on e.ip = r.ip
41+ left join lookup_international_location FOR SYSTEM_TIME AS OF e.proctime as m on m.code = r.areacode
42+ where
43+ TIMESTAMPDIFF(MINUTE, e.rowtime, LOCALTIMESTAMP) <= 10
44+ group by
45+ e.application_id,
46+ e.main_id,
47+ (
48+ case
49+ when r.province = 'Hongkong' then '22.27747'
50+ WHEN r.province = 'Macao' then '22.16252'
51+ WHEN r.province = 'Taiwan' then '25.04573'
52+ ELSE m.lat
53+ END
54+ ),
55+ (
56+ case
57+ when r.province = 'Hongkong' then '114.1712'
58+ WHEN r.province = 'Macao' then '113.5838'
59+ WHEN r.province = 'Taiwan' then '121.5117'
60+ ELSE m.lng
61+ END
62+ ),
63+ r.areacode,
64+ (
65+ case
66+ when r.province = 'Hongkong' then 'HK'
67+ WHEN r.province = 'Macao' then 'MO'
68+ WHEN r.province = 'Taiwan' then 'TW'
69+ ELSE r.areacode
70+ END
71+ ),
72+ HOP(e.proctime, INTERVAL '10' SECOND, INTERVAL '10' MINUTE);
0 commit comments