14
14
mozfun .glean .parse_datetime(ping_info .end_time ) AS parsed_end_time,
15
15
` moz-fx-data-shared-prod.udf.glean_timespan_seconds` ( metrics .timespan .glean_baseline_duration ) AS duration,
16
16
metadata .geo .city,
17
- metadata .geo .subdivision1 AS geo_subdivision1,
18
- metadata .geo .subdivision2 AS geo_subdivision2,
17
+ metadata .geo .subdivision1 AS subdivision1,
18
+ metadata .geo .subdivision2 AS subdivision2,
19
+ metadata .geo .country AS country,
19
20
FROM
20
21
` {{ project_id }}.{{ app_id }}_stable.baseline_v1`
21
22
WHERE
56
57
client_id,
57
58
sample_id,
58
59
ROW_NUMBER() OVER w1_unframed AS _n,
59
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(city) OVER w1) AS city,
60
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(geo_subdivision1) OVER w1) AS geo_subdivision1,
61
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(geo_subdivision2) OVER w1) AS geo_subdivision2,
60
+ ` moz-fx-data-shared-prod.udf.mode_last_retain_nulls` (
61
+ ARRAY_AGG(STRUCT(
62
+ city AS city,
63
+ subdivision1 AS subdivision1,
64
+ subdivision2 AS subdivision2,
65
+ country AS country
66
+ )
67
+ ) OVER w1
68
+ ) AS geo,
62
69
FROM
63
70
with_date_offsets_{{ app_id }}
64
71
LEFT JOIN
91
98
FROM
92
99
windowed_{{ app_id }} AS cd
93
100
WHERE
94
- _n = 1 ),
101
+ _n = 1 AND geo . city IS NOT NULL ),
95
102
clients_city_first_seen_{{ app_id }} AS (
96
103
SELECT
97
104
client_id,
98
105
sample_id,
99
- submission_date AS first_seen_geo_date,
100
- city AS first_seen_geo_city,
101
- geo_subdivision1 AS first_seen_geo_subdivision1,
102
- geo_subdivision2 AS first_seen_geo_subdivision2,
106
+ submission_date AS first_seen_city_date,
107
+ geo .city AS first_seen_city,
108
+ geo .subdivision1 AS first_seen_subdivision1,
109
+ geo .subdivision2 AS first_seen_subdivision2,
110
+ geo .country AS first_seen_country,
103
111
FROM
104
112
clients_daily_{{ app_id }}
105
113
QUALIFY
@@ -108,10 +116,11 @@ clients_city_first_seen_{{ app_id }} AS (
108
116
SELECT
109
117
client_id,
110
118
sample_id,
111
- submission_date AS last_seen_geo_date,
112
- city AS last_seen_geo_city,
113
- geo_subdivision1 AS last_seen_geo_subdivision1,
114
- geo_subdivision2 AS last_seen_geo_subdivision2,
119
+ submission_date AS last_seen_city_date,
120
+ geo .city AS last_seen_city,
121
+ geo .subdivision1 AS last_seen_subdivision1,
122
+ geo .subdivision2 AS last_seen_subdivision2,
123
+ geo .country AS last_seen_country,
115
124
FROM
116
125
clients_daily_{{ app_id }}
117
126
QUALIFY
@@ -122,20 +131,21 @@ SELECT
122
131
" {{ app_id }}" AS app_id,
123
132
COALESCE(cfs .client_id , cls .client_id ) AS client_id,
124
133
COALESCE(cfs .sample_id , cls .sample_id ) AS sample_id,
125
- first_seen_geo_date,
126
- first_seen_geo_city,
127
- first_seen_geo_subdivision1,
128
- first_seen_geo_subdivision2,
129
- last_seen_geo_date,
130
- last_seen_geo_city,
131
- last_seen_geo_subdivision1,
132
- last_seen_geo_subdivision2,
134
+ first_seen_city_date,
135
+ first_seen_city,
136
+ first_seen_subdivision1,
137
+ first_seen_subdivision2,
138
+ first_seen_country,
139
+ last_seen_city_date,
140
+ last_seen_city,
141
+ last_seen_subdivision1,
142
+ last_seen_subdivision2,
143
+ last_seen_country,
133
144
FROM
134
145
clients_city_first_seen_{{ app_id }} cfs
135
146
FULL OUTER JOIN
136
147
clients_city_last_seen_{{ app_id }} cls
137
- ON
138
- cfs .client_id = cls .client_id
148
+ ON cfs .client_id = cls .client_id
139
149
AND cfs .sample_id = cls .sample_id
140
150
{{ " UNION ALL" if not loop .last }}
141
151
{% endfor - %}
@@ -157,14 +167,16 @@ _current_windowed_{{ app_id }} AS (
157
167
client_info .client_id AS client_id,
158
168
sample_id,
159
169
ROW_NUMBER() OVER w1_unframed AS _n,
160
- @submission_date AS first_seen_geo_date,
161
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .city) OVER w1) AS first_seen_geo_city,
162
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .subdivision1) OVER w1) AS first_seen_geo_subdivision1,
163
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .subdivision2) OVER w1) AS first_seen_geo_subdivision2,
164
- @submission_date AS last_seen_geo_date,
165
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .city) OVER w1) AS last_seen_geo_city,
166
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .subdivision1) OVER w1) AS last_seen_geo_subdivision1,
167
- ` moz-fx-data-shared-prod.udf.mode_last` (ARRAY_AGG(metadata .geo .subdivision2) OVER w1) AS last_seen_geo_subdivision2,
170
+ submission_date,
171
+ ` moz-fx-data-shared-prod.udf.mode_last_retain_nulls` (
172
+ ARRAY_AGG(STRUCT(
173
+ city AS city,
174
+ subdivision1 AS subdivision1,
175
+ subdivision2 AS subdivision2,
176
+ country AS country
177
+ )
178
+ ) OVER w1
179
+ ) AS geo,
168
180
FROM
169
181
` moz-fx-data-shared-prod.{{ app_id }}_live.baseline_v1`
170
182
WHERE
@@ -189,40 +201,73 @@ _current_windowed_{{ app_id }} AS (
189
201
_current_{{ app_id }} AS (
190
202
SELECT
191
203
cw.* EXCEPT (_n),
204
+ submission_date AS first_seen_city_date,
205
+ geo .city AS first_seen_city,
206
+ geo .subdivision1 AS first_seen_subdivision1,
207
+ geo .subdivision2 AS first_seen_subdivision2,
208
+ geo .country AS first_seen_country,
209
+ submission_date AS last_seen_city_date,
210
+ geo .city AS last_seen_city,
211
+ geo .subdivision1 AS last_seen_subdivision1,
212
+ geo .subdivision2 AS last_seen_subdivision2,
213
+ geo .country AS last_seen_country
192
214
FROM
193
215
_current_windowed_{{ app_id }} AS cw
194
216
WHERE
195
- _n = 1 ){{ " ," if not loop .last }}
217
+ _n = 1
218
+ AND geo .city IS NOT NULL ){{ " ," if not loop .last }}
196
219
{% endfor - %}
197
220
{% for app_id in app_id_list - %}
198
221
SELECT
199
222
app_id,
200
223
client_id,
201
224
sample_id,
202
225
IF
203
- (_p .client_id IS NULL , _c .first_seen_geo_date , _p .first_seen_geo_date ) AS first_seen_geo_date,
226
+ (_p .client_id IS NULL ,
227
+ _c .first_seen_city_date ,
228
+ _p .first_seen_city_date
229
+ ) AS first_seen_city_date,
204
230
IF
205
- (_p .client_id IS NULL , _c .first_seen_geo_city , _p .first_seen_geo_city ) AS first_seen_geo_city,
231
+ (_p .client_id IS NULL ,
232
+ _c .first_seen_city ,
233
+ _p .first_seen_city
234
+ ) AS first_seen_city,
206
235
IF
207
- (_p .client_id IS NULL , _c .first_seen_geo_subdivision1 , _p .first_seen_geo_subdivision1 ) AS first_seen_geo_subdivision1,
236
+ (_p .client_id IS NULL ,
237
+ _c .first_seen_subdivision1 ,
238
+ _p .first_seen_subdivision1
239
+ ) AS first_seen_subdivision1,
208
240
IF
209
- (_p .client_id IS NULL , _c .first_seen_geo_subdivision2 , _p .first_seen_geo_subdivision2 ) AS first_seen_geo_subdivision2,
241
+ (_p .client_id IS NULL ,
242
+ _c .first_seen_subdivision2 ,
243
+ _p .first_seen_subdivision2
244
+ ) AS first_seen_subdivision2,
210
245
IF
211
- (_p .last_seen_geo_date < _c .last_seen_geo_date , _c .last_seen_geo_date , _p .last_seen_geo_date ) AS last_seen_geo_date,
246
+ (_p .last_seen_city_date < _c .last_seen_city_date ,
247
+ _c .last_seen_city_date ,
248
+ _p .last_seen_city_date
249
+ ) AS last_seen_city_date,
212
250
IF
213
- (_p .last_seen_geo_date < _c .last_seen_geo_date , _c .last_seen_geo_city , _p .last_seen_geo_city ) AS last_seen_geo_city,
251
+ (_p .last_seen_city_date < _c .last_seen_city_date ,
252
+ _c .last_seen_city ,
253
+ _p .last_seen_city
254
+ ) AS last_seen_city,
214
255
IF
215
- (_p .last_seen_geo_date < _c .last_seen_geo_date , _c .last_seen_geo_subdivision1 , _p .last_seen_geo_subdivision1 ) AS last_seen_geo_subdivision1,
256
+ (_p .last_seen_city_date < _c .last_seen_city_date ,
257
+ _c .last_seen_subdivision1 ,
258
+ _p .last_seen_subdivision1
259
+ ) AS last_seen_subdivision1,
216
260
IF
217
- (_p .last_seen_geo_date < _c .last_seen_geo_date , _c .last_seen_geo_subdivision2 , _p .last_seen_geo_subdivision2 ) AS last_seen_geo_subdivision2,
261
+ (_p .last_seen_city_date < _c .last_seen_city_date ,
262
+ _c .last_seen_subdivision2 ,
263
+ _p .last_seen_subdivision2
264
+ ) AS last_seen_subdivision2,
218
265
FROM
219
266
_current_{{ app_id }} AS _c
220
267
FULL JOIN
221
268
_previous_{{ app_id }} AS _p
222
269
USING
223
- (client_id,
224
- sample_id,
225
- app_id)
270
+ (client_id, sample_id, app_id)
226
271
{{ " UNION ALL" if not loop .last }}
227
272
{% endfor - %}
228
273
{% raw %}
0 commit comments