-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathdata_attribute_total.sql
More file actions
38 lines (33 loc) · 1 KB
/
data_attribute_total.sql
File metadata and controls
38 lines (33 loc) · 1 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
CREATE TEMPORARY FUNCTION get_almanac_attribute_info(almanac_string STRING)
RETURNS ARRAY<STRUCT<name STRING, freq INT64>> LANGUAGE js AS '''
try {
var almanac = JSON.parse(almanac_string);
if (Array.isArray(almanac) || typeof almanac != 'object') return [];
if (almanac.attributes_used_on_elements) {
return Object.entries(almanac.attributes_used_on_elements).filter(([name, freq]) => name.startsWith('data-')).map(([name, freq]) => ({name, freq}));
}
} catch (e) {}
return [];
''';
WITH totals AS (
SELECT
_TABLE_SUFFIX,
COUNT(0) AS total_pages
FROM
`httparchive.pages.2022_06_01_*`
GROUP BY
_TABLE_SUFFIX
)
SELECT
_TABLE_SUFFIX AS client,
COUNT(DISTINCT url) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT url) / ANY_VALUE(total_pages) AS pct_pages
FROM
`httparchive.pages.2022_06_01_*`
JOIN
totals
USING (_TABLE_SUFFIX),
UNNEST(get_almanac_attribute_info(JSON_EXTRACT_SCALAR(payload, '$._almanac'))) AS almanac_attribute_info
GROUP BY
client