Skip to content

Commit

Permalink
sql unstead of custom fnct
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Dec 17, 2024
1 parent df280a1 commit d0c9143
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions definitions/output/reports/cwv_tech_adoption.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ publish('cwv_tech_adoption', {
},
tags: ['crux_ready']
}).preOps(ctx => `
CREATE TEMPORARY FUNCTION GET_ADOPTION(
records ARRAY<STRUCT<
client STRING,
origins INT64
>>)
RETURNS STRUCT<
desktop INT64,
mobile INT64
>
LANGUAGE js AS '''
return Object.fromEntries(
records.map(({client, origins}) => {
return [client, origins]
}))
''';
DELETE FROM ${ctx.self()}
WHERE date = '${pastMonth}';
`).query(ctx => `
Expand All @@ -35,10 +19,10 @@ SELECT
app AS technology,
rank,
geo,
GET_ADOPTION(ARRAY_AGG(STRUCT(
client,
origins
))) AS adoption
STRUCT(
COALESCE(MAX(IF(client = 'desktop', origins, NULL))) AS desktop,
COALESCE(MAX(IF(client = 'mobile', origins, NULL))) AS mobile
) AS adoption
FROM ${ctx.ref('core_web_vitals', 'technologies')}
WHERE date = '${pastMonth}'
GROUP BY
Expand Down

0 comments on commit d0c9143

Please sign in to comment.