Skip to content

Commit d0c9143

Browse files
committed
sql unstead of custom fnct
1 parent df280a1 commit d0c9143

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

definitions/output/reports/cwv_tech_adoption.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ publish('cwv_tech_adoption', {
1010
},
1111
tags: ['crux_ready']
1212
}).preOps(ctx => `
13-
CREATE TEMPORARY FUNCTION GET_ADOPTION(
14-
records ARRAY<STRUCT<
15-
client STRING,
16-
origins INT64
17-
>>)
18-
RETURNS STRUCT<
19-
desktop INT64,
20-
mobile INT64
21-
>
22-
LANGUAGE js AS '''
23-
return Object.fromEntries(
24-
records.map(({client, origins}) => {
25-
return [client, origins]
26-
}))
27-
''';
28-
2913
DELETE FROM ${ctx.self()}
3014
WHERE date = '${pastMonth}';
3115
`).query(ctx => `
@@ -35,10 +19,10 @@ SELECT
3519
app AS technology,
3620
rank,
3721
geo,
38-
GET_ADOPTION(ARRAY_AGG(STRUCT(
39-
client,
40-
origins
41-
))) AS adoption
22+
STRUCT(
23+
COALESCE(MAX(IF(client = 'desktop', origins, NULL))) AS desktop,
24+
COALESCE(MAX(IF(client = 'mobile', origins, NULL))) AS mobile
25+
) AS adoption
4226
FROM ${ctx.ref('core_web_vitals', 'technologies')}
4327
WHERE date = '${pastMonth}'
4428
GROUP BY

0 commit comments

Comments
 (0)