Skip to content

Commit af0c58a

Browse files
committed
feat: update terms_of_use_status_v1 template to overwrite the table on each run.
1 parent 0195628 commit af0c58a

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

sql_generators/terms_of_use/templates/terms_of_use_status_v1/bigconfig.yml.jinja

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ table_deployments:
1111
- saved_metric_id: volume
1212
- saved_metric_id: freshness
1313
columns:
14-
- column_name: submission_date
14+
- column_name: submission_timestamp
1515
metrics:
1616
- saved_metric_id: is_not_null
17-
- column_name: country
17+
- column_name: client_id
18+
metrics:
19+
- saved_metric_id: is_not_null
20+
- column_name: normalized_country_code
1821
metrics:
1922
- saved_metric_id: is_2_char_len
2023
- column_name: normalized_channel

sql_generators/terms_of_use/templates/terms_of_use_status_v1/metadata.yaml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: |-
88
owners:
99
1010
labels:
11-
incremental: false -- TODO: do we want to keep history for each client and then have a layer on top getting the most recent state?
11+
incremental: true
1212
schedule: daily
1313
table_type: client_level
1414
scheduling:

sql_generators/terms_of_use/templates/terms_of_use_status_v1/query.sql.jinja

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
-- {{ header }}
2-
SELECT
2+
WITH _previous AS (
3+
SELECT
4+
submission_timestamp,
5+
client_info.client_id,
6+
app_version_major
7+
app_version_minor,
8+
app_version_patch,
9+
normalized_channel,
10+
normalized_country_code,
11+
normalized_os,
12+
normalized_os_version,
13+
is_bot_generated,
14+
isp_name,
15+
terms_of_use_version_accepted,
16+
terms_of_use_date_accepted,
17+
{% if app_name == "firefox_desktop" %}
18+
metrics.metrics.uuid.legacy_telemetry_client_id, -- firefox_desktop exclusive field.
19+
{% endif %}
20+
FROM
21+
`{{ project_id }}.{{ app_name }}_derived.{{ table_name }}`
22+
WHERE
23+
DATE(submission_timestamp) <= @submission_date
24+
),
25+
_current AS (
26+
SELECT
327
submission_timestamp,
428
client_info.client_id,
5-
app_version_major, -- noticed a few entries with version 9000, should those be excluded?
29+
app_version_major,
630
app_version_minor,
731
app_version_patch,
832
normalized_channel,
@@ -11,7 +35,6 @@ SELECT
1135
normalized_os_version,
1236
is_bot_generated,
1337
metadata.isp.name AS isp_name,
14-
-- update entry if either of these change:
1538
{% if app_name == "firefox_ios" %}
1639
metrics.metrics.quantity.user_terms_of_use_version_accepted AS terms_of_use_version_accepted,
1740
metrics.metrics.datetime.user_terms_of_use_date_accepted AS terms_of_use_date_accepted,
@@ -29,3 +52,18 @@ WHERE
2952
DATE(submission_timestamp) >= {% if app_name == "firefox_desktop" %}"2025-06-24"{% else %}"2025-09-15"{% endif %}
3053
AND app_version_major >= 142
3154
AND metrics.metrics.datetime.user_terms_of_use_date_accepted IS NOT NULL
55+
)
56+
57+
SELECT
58+
-- update entry if `terms_of_use_version_accepted` or `terms_of_use_date_accepted` value changes:
59+
IF(
60+
(_current.terms_of_use_version_accepted <> _previous.terms_of_use_version_accepted)
61+
OR (_current.terms_of_use_date_accepted <> _previous.terms_of_use_date_accepted),
62+
_current,
63+
_previous
64+
).*
65+
FROM
66+
_previous
67+
FULL OUTER JOIN _current
68+
USING (client_id, normalized_channel)
69+

0 commit comments

Comments
 (0)