Skip to content

Commit 0f63b30

Browse files
committed
feat: set string value for app_channel when null prior to join
1 parent 59a52e8 commit 0f63b30

3 files changed

+18
-33
lines changed

sql_generators/usage_reporting/templates/usage_reporting_clients_first_seen_v1.query.sql.jinja

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,26 @@ WITH
1010
@submission_date AS first_seen_date,
1111
{% endif %}
1212
{% endraw %}
13-
{% if app_name == "firefox_desktop" %}
14-
app_channel,
15-
{% endif %}
13+
IFNULL(app_channel, "") AS app_channel,
1614
FROM
1715
`{{ project_id }}.{{ channel_dataset }}.usage_reporting_clients_daily`
1816
WHERE
1917
usage_profile_id IS NOT NULL
20-
{% raw %}
21-
{% if is_init() %}
18+
{% raw %}
19+
{% if is_init() %}
2220
AND submission_date > "2014-10-10"
23-
{% else %}
24-
AND submission_date = @submission_date
25-
{% endif %}
26-
{% endraw %}
2721
GROUP BY
28-
usage_profile_id
29-
{% if app_name == "firefox_desktop" %}
30-
, app_channel
31-
{% endif %}
22+
usage_profile_id,
23+
app_channel
24+
{% else %}
25+
AND submission_date = @submission_date
26+
{% endif %}
27+
{% endraw %}
3228
),
3329
_previous AS (
3430
SELECT
3531
usage_profile_id,
36-
{% if app_name == "firefox_desktop" %}
37-
app_channel,
38-
{% endif %}
32+
IFNULL(app_channel, "") AS app_channel,
3933
FROM
4034
`{{ project_id }}.{{ channel_dataset }}_derived.{{ view_name }}_v1`
4135
WHERE
@@ -51,16 +45,12 @@ _previous AS (
5145
SELECT
5246
first_seen_date,
5347
usage_profile_id,
54-
{% if app_name == "firefox_desktop" %}
55-
-- app_channel is only needed on desktop as the single namespace
56-
-- contains data for all channel unlike the mobile apps.
57-
app_channel,
58-
{% endif %}
48+
NULLIF(app_channel, "") AS app_channel,
5949
FROM
6050
_current
6151
LEFT JOIN
6252
_previous
63-
USING (usage_profile_id {% if app_name == "firefox_desktop" %}, app_channel{% endif %})
53+
USING (usage_profile_id, app_channel)
6454
WHERE
6555
_previous.usage_profile_id IS NULL
6656
QUALIFY

sql_generators/usage_reporting/templates/usage_reporting_clients_first_seen_v1.schema.yaml.jinja

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ fields:
1212
description: |
1313
A UUID of the usage_profile.
1414

15-
{% if app_name == "firefox_desktop" %}
16-
# app_channel is only needed on desktop as the single namespace
17-
# contains data for all channel unlike the mobile apps.
1815
- mode: NULLABLE
1916
name: app_channel
2017
type: STRING
2118
description: |
22-
The channel the application is being distributed on.
23-
{% endif %}
19+
The channel the application is being distributed on, on mobile this is expected to be mostly null.

sql_generators/usage_reporting/templates/usage_reporting_clients_last_seen_v1.query.sql.jinja

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
WITH _current AS (
55
SELECT
66
usage_profile_id,
7-
app_channel,
7+
IFNULL(app_channel, "") AS app_channel,
88
-- The rightmost bit in 'days_since_seen' represents whether the user sent a usage_reporting ping on the submission_date.
99
CAST(TRUE AS INT64) AS days_seen_bits,
1010
-- The rightmost bit in days_active_bits represents whether the user counts as active on the submission_date.
@@ -20,7 +20,7 @@ WITH _current AS (
2020
_previous AS (
2121
SELECT
2222
usage_profile_id,
23-
app_channel,
23+
IFNULL(app_channel, "") AS app_channel,
2424
days_seen_bits,
2525
days_active_bits,
2626
days_created_profile_bits,
@@ -45,12 +45,11 @@ SELECT
4545
udf.combine_adjacent_days_28_bits(
4646
_previous.days_created_profile_bits,
4747
_current.days_created_profile_bits
48-
) AS days_created_profile_bits
48+
) AS days_created_profile_bits,
49+
NULLIF(app_channel, "") AS app_channel
4950
)
5051
FROM
5152
_current
5253
FULL JOIN
5354
_previous
54-
-- TODO: should we be using app_channel for join here?
55-
-- or are we 100% confident usage_profile_id will always be unique across channels?
56-
USING (usage_profile_id)
55+
USING (usage_profile_id, app_channel)

0 commit comments

Comments
 (0)