Last active
October 11, 2022 21:41
-
-
Save tomvangoethem/6f09d5a5c000cacfab6c258a650d4bb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TEMPORARY FUNCTION | |
getIframeHosts(payload STRING) | |
RETURNS ARRAY<STRING> | |
LANGUAGE js AS ''' | |
try { | |
const almanac = JSON.parse(payload); | |
return almanac.iframes.iframes.nodes.map(x => x.src).filter(x => x).map(x => x.replace(new RegExp('^//'), 'https://')).filter(x => x.indexOf('http') === 0); | |
} catch (e) { | |
return []; | |
} | |
'''; | |
WITH | |
hosts AS ( | |
SELECT | |
NET.HOST(src) AS host, | |
COUNT(1) AS num, | |
ARRAY_AGG(STRUCT(url, | |
src) | |
ORDER BY | |
RAND() | |
LIMIT | |
50) AS sample, | |
FROM ( | |
SELECT | |
url, | |
getIframeHosts(JSON_EXTRACT_SCALAR(payload, '$._almanac')) AS sources | |
FROM | |
`httparchive.pages.2022_09_01_desktop` ), | |
UNNEST(sources) AS src | |
GROUP BY | |
host ), | |
totals AS ( | |
SELECT | |
COUNT(1) AS total | |
FROM | |
`httparchive.pages.2022_09_01_desktop` ) | |
SELECT | |
host, | |
num, | |
num / total * 100.0 AS pct, | |
sample | |
FROM | |
hosts | |
FULL OUTER JOIN | |
totals | |
ON | |
(TRUE) | |
ORDER BY | |
num DESC | |
LIMIT | |
10000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment