-
Notifications
You must be signed in to change notification settings - Fork 4
/
athena-tables.sql
89 lines (80 loc) · 3.02 KB
/
athena-tables.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
86
87
88
89
CREATE EXTERNAL TABLE `raw_events_code`(
`querystring` string COMMENT 'from deserializer',
`event` string COMMENT 'from deserializer',
`datetime` timestamp COMMENT 'from deserializer')
PARTITIONED BY (
`date` string,
`hour` int)
ROW FORMAT SERDE
'org.apache.hive.hcatalog.data.JsonSerDe'
WITH SERDEPROPERTIES (
'timestamp.formats'='yyyy-MM-dd\'T\'HH:mm:ss')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://<CODE_BUCKET>/fastly';
CREATE EXTERNAL TABLE `raw_events_prod`(
`querystring` string COMMENT 'from deserializer',
`event` string COMMENT 'from deserializer',
`datetime` timestamp COMMENT 'from deserializer')
PARTITIONED BY (
`date` string,
`hour` int)
ROW FORMAT SERDE
'org.apache.hive.hcatalog.data.JsonSerDe'
WITH SERDEPROPERTIES (
'timestamp.formats'='yyyy-MM-dd\'T\'HH:mm:ss')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://<PROD_BUCKET>/fastly';
CREATE OR REPLACE VIEW notification_received_prod AS
SELECT
"dateTime" "received_timestamp",
"regexp_extract"("querystring", 'notificationId=([\w-]+)', 1) "notificationId",
"regexp_extract"("querystring", 'platform=(\w+)', 1) "platform",
"regexp_extract"("querystring", 'provider=(\w+)', 1) "provider",
"date" "partition_date",
"hour" "partition_hour"
FROM
notifications.raw_events_prod
WHERE
event = '/notification/received';
CREATE OR REPLACE VIEW notification_received_code AS
SELECT
"dateTime" "received_timestamp",
"regexp_extract"("querystring", 'notificationId=([\w-]+)', 1) "notificationId",
"regexp_extract"("querystring", 'platform=(\w+)', 1) "platform",
"regexp_extract"("querystring", 'provider=(\w+)', 1) "provider",
"date" "partition_date",
"hour" "partition_hour"
FROM
notifications.raw_events_code
WHERE
event = '/notification/received';
CREATE OR REPLACE VIEW notification_received_72h_prod AS
SELECT
"dateTime" "received_timestamp",
"regexp_extract"("querystring", 'notificationId=([\w-]+)', 1) "notificationId",
"regexp_extract"("querystring", 'platform=(\w+)', 1) "platform",
"regexp_extract"("querystring", 'provider=(\w+)', 1) "provider",
"date" "partition_date",
"hour" "partition_hour"
FROM
notifications.raw_events_prod
WHERE ("from_iso8601_date"("date") >= ("from_iso8601_date"("date") - INTERVAL '3' DAY));
CREATE OR REPLACE VIEW notification_received_72h_code AS
SELECT
"dateTime" "received_timestamp",
"regexp_extract"("querystring", 'notificationId=([\w-]+)', 1) "notificationId",
"regexp_extract"("querystring", 'platform=(\w+)', 1) "platform",
"regexp_extract"("querystring", 'provider=(\w+)', 1) "provider",
"date" "partition_date",
"hour" "partition_hour"
FROM
notifications.raw_events_code
WHERE ("from_iso8601_date"("date") >= ("from_iso8601_date"("date") - INTERVAL '3' DAY));