From d6a55664d0d056e2156b67791162f023aa5b0128 Mon Sep 17 00:00:00 2001 From: Linh Nguyen Date: Tue, 6 Jun 2023 14:41:03 -0400 Subject: [PATCH] Revert "Simplify GLAM template for getting latest versions (#3880)" (#3908) This reverts commit 8ad45a0592f5d05e7a5105be30e41b6d2b0d8119. --- bigquery_etl/glam/generate.py | 16 +++----- .../glam/templates/latest_versions_v1.sql | 40 +++++++++++++++---- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/bigquery_etl/glam/generate.py b/bigquery_etl/glam/generate.py index 8ca6679a33..ed30cd807d 100644 --- a/bigquery_etl/glam/generate.py +++ b/bigquery_etl/glam/generate.py @@ -28,16 +28,6 @@ class TemplateResult: query_text: str -APP_PREFIX_CHANNELS = { - "firefox_desktop_glam_nightly": "nightly", - "firefox_desktop_glam_beta": "beta", - "firefox_desktop_glam_release": "release", - "org_mozilla_fenix_glam_nightly": "nightly", - "org_mozilla_fenix_glam_beta": "beta", - "org_mozilla_fenix_glam_release": "release", -} - - def from_template( query_type: QueryType, template_name: str, @@ -223,7 +213,11 @@ def main(): [ table( "latest_versions_v1", - **dict(app_id_channel=(f"'{APP_PREFIX_CHANNELS[args.prefix]}'")), + **dict( + source_table=( + f"glam_etl.{args.prefix}__view_clients_daily_scalar_aggregates_v1" + ) + ), ), init( "clients_scalar_aggregates_v1", diff --git a/bigquery_etl/glam/templates/latest_versions_v1.sql b/bigquery_etl/glam/templates/latest_versions_v1.sql index 12e4c53ccd..d4bf758296 100644 --- a/bigquery_etl/glam/templates/latest_versions_v1.sql +++ b/bigquery_etl/glam/templates/latest_versions_v1.sql @@ -1,12 +1,36 @@ {{ header }} +WITH extracted AS ( + SELECT + client_id, + channel, + app_version + FROM + {{ source_table }} + WHERE + submission_date + BETWEEN DATE_SUB(@submission_date, INTERVAL 28 DAY) + AND @submission_date + AND channel IS NOT NULL +), +transformed AS ( + SELECT + channel, + app_version + FROM + extracted + GROUP BY + channel, + app_version + HAVING + COUNT(DISTINCT client_id) > 5 + ORDER BY + channel, + app_version DESC +) SELECT - build.`target`.channel AS channel, - MAX(mozfun.norm.extract_version(build.`target`.version, - 'major')) AS latest_version + channel, + MAX(app_version) AS latest_version FROM - `moz-fx-data-shared-prod.telemetry.buildhub2` -WHERE - build.`source`.product = "firefox" - AND build.`target`.channel = {{ app_id_channel }} + transformed GROUP BY - build.`target`.channel + channel