Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Capabilities queries #2322

Merged
merged 11 commits into from
Aug 30, 2021
Merged
39 changes: 39 additions & 0 deletions sql/2021/capabilities/fugu.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#standardSQL
CREATE TEMP FUNCTION getFuguAPIs(data STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS '''
const $ = JSON.parse(data);
return Object.keys($);
''';

SELECT
_TABLE_SUFFIX AS client,
fuguAPI,
COUNT(DISTINCT url) AS pages,
total,
COUNT(DISTINCT url) / total AS pct,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT url LIMIT 50), ' ') AS sample_urls
FROM
`httparchive.pages.2021_07_01_*`
JOIN (
SELECT
_TABLE_SUFFIX,
COUNT(0) AS total
FROM
`httparchive.pages.2021_07_01_*`
GROUP BY
_TABLE_SUFFIX)
USING
(_TABLE_SUFFIX),
UNNEST(getFuguAPIs(JSON_QUERY(payload, '$."_fugu-apis"'))) AS fuguAPI
WHERE
JSON_QUERY(payload, '$."_fugu-apis"') != "[]"
GROUP BY
fuguAPI,
client,
total
HAVING
COUNT(DISTINCT url) >= 10
ORDER BY
pct DESC,
client;
27 changes: 27 additions & 0 deletions sql/2021/capabilities/top.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#standardSQL
CREATE TEMP FUNCTION getFuguAPIs(data STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS '''
const $ = JSON.parse(data);
return Object.keys($);
''';

SELECT
_TABLE_SUFFIX AS client,
url,
COUNT(DISTINCT fuguAPI) AS fuguAPIs
FROM
`httparchive.pages.2021_07_01_*`,
UNNEST(getFuguAPIs(JSON_QUERY(payload, '$."_fugu-apis"'))) AS fuguAPI
WHERE
JSON_QUERY(payload, '$."_fugu-apis"') != "[]"
GROUP BY
client,
url
HAVING
COUNT(DISTINCT fuguAPI) >= 1
ORDER BY
fuguAPIs DESC,
url,
client
LIMIT 100;