diff --git a/sql_generators/mobile_kpi_support_metrics/templates/active_users.view.sql b/sql_generators/mobile_kpi_support_metrics/templates/active_users.view.sql index fb491b08cbc..3972fcf6858 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/active_users.view.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/active_users.view.sql @@ -3,10 +3,7 @@ CREATE OR REPLACE VIEW `{{ project_id }}.{{ dataset }}.{{ name }}` AS SELECT - * EXCEPT (isp) REPLACE( - -- Lower device_manufacturer as in some cases the same manufacturer value has different casing. - LOWER(device_manufacturer) AS device_manufacturer - ), + * EXCEPT (isp), CASE WHEN LOWER(isp) = "browserstack" THEN CONCAT("{{ friendly_name }}", " ", isp) @@ -60,5 +57,8 @@ SELECT ELSE CAST(NULL AS STRING) END AS device_type, + -- Lower device_manufacturer as in some cases the same manufacturer value has different casing. + -- But keeping the original value to not create a sudden impact on downstream calculations. + LOWER(device_manufacturer) AS device_manufacturer_lowered, FROM `{{ project_id }}.{{ dataset }}.baseline_clients_last_seen` diff --git a/sql_generators/mobile_kpi_support_metrics/templates/engagement.query.sql b/sql_generators/mobile_kpi_support_metrics/templates/engagement.query.sql index e6ef72badd9..22a46f1d192 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/engagement.query.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/engagement.query.sql @@ -2,8 +2,8 @@ WITH device_manufacturer_counts AS ( SELECT submission_date, - device_manufacturer, - DENSE_RANK() OVER(PARTITION BY submission_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, + device_manufacturer_lowered, + RANK() OVER(PARTITION BY submission_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, FROM `{{ project_id }}.{{ dataset }}.engagement_clients` WHERE @@ -16,7 +16,7 @@ WITH device_manufacturer_counts AS ( {% endraw %} GROUP BY submission_date, - device_manufacturer + device_manufacturer_lowered ) SELECT @@ -36,12 +36,12 @@ SELECT COUNTIF(is_mau) AS mau, device_type, -- Bucket device manufacturers with low count prior to aggregation - IF(manufacturer_rank <= 150, device_manufacturer, "other") AS device_manufacturer, + IF(manufacturer_rank <= 150, device_manufacturer_lowered, "other") AS device_manufacturer, FROM `{{ project_id }}.{{ dataset }}.engagement_clients` LEFT JOIN device_manufacturer_counts - USING(submission_date, device_manufacturer) + USING(submission_date, device_manufacturer_lowered) WHERE {% raw %} {% if is_init() %} diff --git a/sql_generators/mobile_kpi_support_metrics/templates/engagement_clients.view.sql b/sql_generators/mobile_kpi_support_metrics/templates/engagement_clients.view.sql index 5dd40e90a3a..3edd3a4fa50 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/engagement_clients.view.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/engagement_clients.view.sql @@ -19,7 +19,7 @@ WITH active_users AS ( is_mau, is_mobile, device_type, - device_manufacturer, + device_manufacturer_lowered, FROM `{{ project_id }}.{{ dataset }}.active_users` ), @@ -65,7 +65,7 @@ SELECT ELSE 'Unknown' END AS lifecycle_stage, device_type, - device_manufacturer, + device_manufacturer_lowered, FROM active_users LEFT JOIN diff --git a/sql_generators/mobile_kpi_support_metrics/templates/new_profile_clients.view.sql b/sql_generators/mobile_kpi_support_metrics/templates/new_profile_clients.view.sql index 9d49e965164..7675185add4 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/new_profile_clients.view.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/new_profile_clients.view.sql @@ -14,7 +14,7 @@ SELECT normalized_os AS os, normalized_os_version AS os_version, device_model, - device_manufacturer, + device_manufacturer_lowered, is_mobile, {% for attribution_field in product_attribution_fields %} attribution.{{ attribution_field }}, diff --git a/sql_generators/mobile_kpi_support_metrics/templates/new_profiles.query.sql b/sql_generators/mobile_kpi_support_metrics/templates/new_profiles.query.sql index c5fedabe8da..05c50db930b 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/new_profiles.query.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/new_profiles.query.sql @@ -2,8 +2,8 @@ WITH device_manufacturer_counts AS ( SELECT first_seen_date, - device_manufacturer, - DENSE_RANK() OVER(PARTITION BY submission_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, + device_manufacturer_lowered, + RANK() OVER(PARTITION BY first_seen_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, FROM `{{ project_id }}.{{ dataset }}.new_profile_clients` WHERE @@ -16,7 +16,7 @@ WITH device_manufacturer_counts AS ( {% endraw %} GROUP BY first_seen_date, - device_manufacturer + device_manufacturer_lowered ) SELECT @@ -29,7 +29,7 @@ SELECT os, os_version, -- Bucket device manufacturers with low count prior to aggregation - IF(manufacturer_rank <= 150, device_manufacturer, "other") AS device_manufacturer, + IF(manufacturer_rank <= 150, device_manufacturer_lowered, "other") AS device_manufacturer, is_mobile, {% for field in product_attribution_fields.values() if not field.client_only %} {{ field.name }}, @@ -40,7 +40,7 @@ FROM `{{ project_id }}.{{ dataset }}.new_profile_clients` LEFT JOIN device_manufacturer_counts - USING(first_seen_date, device_manufacturer) + USING(first_seen_date, device_manufacturer_lowered) WHERE {% raw %} {% if is_init() %} diff --git a/sql_generators/mobile_kpi_support_metrics/templates/retention.query.sql b/sql_generators/mobile_kpi_support_metrics/templates/retention.query.sql index 236879fbaea..4c56e055a48 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/retention.query.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/retention.query.sql @@ -2,8 +2,8 @@ WITH device_manufacturer_counts AS ( SELECT submission_date, - device_manufacturer, - DENSE_RANK() OVER(PARTITION BY submission_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, + device_manufacturer_lowered, + RANK() OVER(PARTITION BY submission_date ORDER BY COUNT(*) DESC) AS manufacturer_rank, FROM `{{ project_id }}.{{ dataset }}.retention_clients` WHERE @@ -18,7 +18,7 @@ WITH device_manufacturer_counts AS ( {% endraw %} GROUP BY submission_date, - device_manufacturer + device_manufacturer_lowered ) SELECT @@ -42,12 +42,12 @@ SELECT COUNTIF(repeat_profile) AS repeat_profiles, device_type, -- Bucket device manufacturers with low count prior to aggregation - IF(manufacturer_rank <= 150, device_manufacturer, "other") AS device_manufacturer, + IF(manufacturer_rank <= 150, device_manufacturer_lowered, "other") AS device_manufacturer, FROM `{{ project_id }}.{{ dataset }}.retention_clients` LEFT JOIN device_manufacturer_counts - USING(submission_date, device_manufacturer) + USING(submission_date, device_manufacturer_lowered) WHERE {% raw %} {% if is_init() %} diff --git a/sql_generators/mobile_kpi_support_metrics/templates/retention_clients.view.sql b/sql_generators/mobile_kpi_support_metrics/templates/retention_clients.view.sql index 221c3fcf0c3..c0c9859118c 100644 --- a/sql_generators/mobile_kpi_support_metrics/templates/retention_clients.view.sql +++ b/sql_generators/mobile_kpi_support_metrics/templates/retention_clients.view.sql @@ -15,7 +15,7 @@ WITH active_users AS ( days_active_bits, is_mobile, device_type, - device_manufacturer, + device_manufacturer_lowered, FROM `{{ project_id }}.{{ dataset }}.active_users` ), @@ -84,7 +84,7 @@ SELECT ELSE 'Unknown' END AS lifecycle_stage, active_users.device_type, - active_users.device_manufacturer, + active_users.device_manufacturer_lowered, FROM `{{ project_id }}.{{ dataset }}.baseline_clients_daily` AS clients_daily INNER JOIN