From 340d4249c21438985988d98be5122c532430e949 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Thu, 20 Jun 2024 12:10:00 +0100 Subject: [PATCH] Rewrite SW query to use blink_features --- sql/timeseries/swControlledPages.sql | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/sql/timeseries/swControlledPages.sql b/sql/timeseries/swControlledPages.sql index 41953eb..2b48b1f 100644 --- a/sql/timeseries/swControlledPages.sql +++ b/sql/timeseries/swControlledPages.sql @@ -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