-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.js
79 lines (78 loc) · 1.52 KB
/
usage.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
publish('usage', {
schema: 'blink_features',
type: 'incremental',
protected: true,
bigquery: {
partitionBy: 'date',
clusterBy: ['client', 'rank', 'feature']
},
description: 'Used in https://lookerstudio.google.com/u/0/reporting/1M8kXOqPkwYNKjJhtag_nvDNJCpvmw_ri/page/tc5b, embedded in https://chromestatus.com/metrics/feature/timeline/popularity/2203',
tags: ['crawl_complete', 'blink_report']
}).preOps(ctx => `
DELETE FROM ${ctx.self()}
WHERE date = '${constants.currentMonth}';
`).query(ctx => `
WITH pages AS (
SELECT
date,
client,
rank,
page,
features
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${constants.currentMonth}' AND
is_root_page = TRUE
${constants.devRankFilter}
), ranks AS (
SELECT DISTINCT rank FROM pages
)
SELECT
date,
client,
rank,
id,
feature,
type,
num_urls,
total_urls,
num_urls / total_urls AS pct_urls,
sample_urls
FROM (
SELECT
date,
client,
ranks.rank,
feature.id,
feature.feature,
feature.type,
COUNT(DISTINCT page) AS num_urls,
ARRAY_AGG(page ORDER BY pages.rank, page LIMIT 100) AS sample_urls
FROM pages
CROSS JOIN UNNEST(features) AS feature
FULL OUTER JOIN ranks
ON pages.rank <= ranks.rank
GROUP BY
date,
client,
ranks.rank,
id,
feature,
type
)
JOIN (
SELECT
date,
client,
ranks.rank,
COUNT(DISTINCT page) AS total_urls
FROM pages
FULL OUTER JOIN ranks
ON pages.rank <= ranks.rank
GROUP BY
date,
client,
ranks.rank
)
USING (date, client, rank)
`)