Skip to content

Instantly share code, notes, and snippets.

@tjmonsi
Last active June 26, 2019 12:49
Show Gist options
  • Save tjmonsi/227c7d25994b6f588a11d3e7f2eb2f46 to your computer and use it in GitHub Desktop.
Save tjmonsi/227c7d25994b6f588a11d3e7f2eb2f46 to your computer and use it in GitHub Desktop.
#standardSQL
-- counts the font types
WITH
summary_requests AS (
SELECT * FROM `httparchive.sample_data.summary_requests_desktop_1k`
UNION ALL
SELECT * FROM `httparchive.sample_data.summary_requests_mobile_1k`
),
processedTable AS (
SELECT
(
IF(STRPOS(mimeType, "font") > 0,
-- get the type of font from the content-type
REGEXP_REPLACE(
REGEXP_REPLACE(mimeType, r"^(font\/x\-)|(font\/font\-)|(font\/)|(application\/font\-)|(application\/x\-font\-)", ""),
r"^x\-",
""
),
-- hack: get the type of font from the file name
ARRAY_REVERSE(
SPLIT(
SPLIT(
ARRAY_REVERSE(
SPLIT(url, "/")
)[OFFSET(0)],
"?"
)[OFFSET(0)],
"."
)
)[OFFSET(0)]
)
) AS font,
*
FROM summary_requests WHERE type = 'font'
)
SELECT
DISTINCT(font),
COUNT(font) AS count
FROM processedTable
GROUP BY font
ORDER BY count DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment