-
-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathcompression_method_by_3p.sql
More file actions
53 lines (52 loc) · 1.32 KB
/
Copy pathcompression_method_by_3p.sql
File metadata and controls
53 lines (52 loc) · 1.32 KB
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
#standardSQL
CREATE TEMPORARY FUNCTION getHeader(headers STRING, headername STRING)
RETURNS STRING
DETERMINISTIC
LANGUAGE js AS '''
const parsed_headers = JSON.parse(headers);
const matching_headers = parsed_headers.filter(h => h.name.toLowerCase() == headername.toLowerCase());
if (matching_headers.length > 0) {
return matching_headers[0].value;
}
return null;
''';
SELECT
client,
host,
compression,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct_pages,
COUNT(0) AS js_requests,
SUM(COUNT(0)) OVER (PARTITION BY client, host) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client, host) AS pct
FROM (
SELECT
client,
page,
IF(NET.HOST(url) IN (
SELECT domain FROM `httparchive.almanac.third_parties` WHERE date = '2020-08-01' AND category != 'hosting'
), 'third party', 'first party') AS host,
getHeader(JSON_EXTRACT(payload, '$.response.headers'), 'Content-Encoding') AS compression
FROM
`httparchive.almanac.requests`
WHERE
date = '2020-08-01' AND
type = 'script'
)
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total_pages
FROM
`httparchive.summary_pages.2020_08_01_*`
GROUP BY
client
)
USING (client)
GROUP BY
client,
host,
compression
ORDER BY
pct DESC