-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtech_report_adoption.js
More file actions
64 lines (61 loc) · 1.5 KB
/
tech_report_adoption.js
File metadata and controls
64 lines (61 loc) · 1.5 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
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
const pastMonth = constants.fnPastMonth(constants.currentMonth)
publish('tech_report_adoption', {
schema: 'reports',
type: 'incremental',
protected: true,
bigquery: {
partitionBy: 'date',
clusterBy: ['rank', 'geo']
},
tags: ['crux_ready']
}).preOps(ctx => `
DELETE FROM ${ctx.self()}
WHERE date = '${pastMonth}';
`).query(ctx => `
SELECT
date,
geo,
rank,
technology,
version,
STRUCT(
MAX(IF(client = 'desktop', origins, 0)) AS desktop,
MAX(IF(client = 'mobile', origins, 0)) AS mobile
) AS adoption
FROM ${ctx.ref('reports', 'tech_crux')}
WHERE date = '${pastMonth}'
GROUP BY
date,
geo,
rank,
technology,
version
`).postOps(ctx => `
SELECT
reports.run_export_job(
JSON '''{
"destination": "firestore",
"config": {
"database": "tech-report-api-${constants.environment}",
"collection": "adoption",
"type": "report",
"date": "${pastMonth}"
},
"query": "SELECT STRING(date) AS date, * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${pastMonth}'"
}'''
);
// legacy export to tech-report-apis database
SELECT
reports.run_export_job(
JSON '''{
"destination": "firestore",
"config": {
"database": "tech-report-apis-${constants.environment}",
"collection": "adoption",
"type": "report",
"date": "${pastMonth}"
},
"query": "SELECT STRING(date) AS date, * EXCEPT(date, version) FROM ${ctx.self()} WHERE date = '${pastMonth}' AND version = 'ALL'"
}'''
);
`)