Skip to content

Commit

Permalink
Rewrite SW query to use blink_features
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Jun 20, 2024
1 parent 59079b9 commit 340d424
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions sql/timeseries/swControlledPages.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
#standardSQL
SELECT
SUBSTR(_TABLE_SUFFIX, 0, 10) AS date,
UNIX_DATE(CAST(REPLACE(SUBSTR(_TABLE_SUFFIX, 0, 10), '_', '-') AS DATE)) * 1000 * 60 * 60 * 24 AS timestamp,
IF(ENDS_WITH(_TABLE_SUFFIX, 'desktop'), 'desktop', 'mobile') AS client,
ROUND(
SUM(
IF(IFNULL(
JSON_EXTRACT(payload, '$._blinkFeatureFirstUsed.Features.ServiceWorkerControlledPage'),
JSON_EXTRACT(payload, '$._blinkFeatureFirstUsed.Features.990')
) IS NOT NULL, 1, 0)
) * 100 / COUNT(0),
2
) AS percent
REGEXP_REPLACE(yyyymmdd, r'(\d{4})(\d{2})(\d{2})', '\\1_\\2_\\3') AS date,
UNIX_DATE(CAST(REGEXP_REPLACE(yyyymmdd, r'(\d{4})(\d{2})(\d{2})', '\\1-\\2-\\3') AS DATE)) * 1000 * 60 * 60 * 24 AS timestamp,
client,
SUM(IF(id = '990' OR feature = 'ServiceWorkerControlledPage', num_urls, 0)) AS num_urls,
ROUND(SUM(IF(id = '990' OR feature = 'ServiceWorkerControlledPage', num_urls, 0)) / total_urls * 100, 5) AS percent
FROM
`httparchive.pages.*`
`httparchive.blink_features.usage`
GROUP BY
date,
timestamp,
client
client,
total_urls
ORDER BY
date DESC,
client
client,
num_urls DESC

0 comments on commit 340d424

Please sign in to comment.