Skip to content

Commit

Permalink
DENG-1935 Change data ordering from pings in clients-first-seen-v2 (#…
Browse files Browse the repository at this point in the history
…4533)

* DENG-1935 Change data ordering from pings in clients-first-seen-v2
* Added main ping for client-3, maintain chosen ping
  • Loading branch information
ANich authored and irrationalagent committed Dec 11, 2023
1 parent 0cf3e0f commit 9e9492c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,28 +412,30 @@ unioned AS (
SELECT
*,
'shutdown' AS source_ping,
3 AS source_ping_priority
2 AS source_ping_priority
FROM
shutdown_ping
UNION ALL
SELECT
*,
'main' AS source_ping,
2 AS source_ping_priority
3 AS source_ping_priority
FROM
main_ping
),
-- The next CTE returns the first_seen_date and reporting ping.
-- The ping type priority is used to prioritize which ping type to select when the timestamp is the same
-- The source_ping_priority and first_seen_timestamp are used to prioritize which ping to select on the first_seen_date
-- The timestamp is retrieved to select the first_seen attributes.
first_seen_date AS (
SELECT
client_id,
DATE(MIN(first_seen_timestamp)) AS first_seen_date,
MIN(first_seen_timestamp) AS first_seen_timestamp,
ARRAY_AGG(source_ping ORDER BY first_seen_timestamp, source_ping_priority)[
ARRAY_AGG(source_ping ORDER BY DATE(first_seen_timestamp), source_ping_priority)[
SAFE_OFFSET(0)
] AS first_seen_source_ping,
ARRAY_AGG(first_seen_timestamp ORDER BY DATE(first_seen_timestamp), source_ping_priority)[
SAFE_OFFSET(0)
] AS first_seen_source_ping
] AS first_seen_source_ping_timestamp
FROM
unioned
GROUP BY
Expand Down Expand Up @@ -492,7 +494,7 @@ _current AS (
ON
(
unioned.client_id = fsd.client_id
AND unioned.first_seen_timestamp = fsd.first_seen_timestamp
AND unioned.first_seen_timestamp = fsd.first_seen_source_ping_timestamp
AND unioned.source_ping = fsd.first_seen_source_ping
)
LEFT JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
sample_id: 30
metadata:
first_seen_date_source_ping: new_profile
reported_main_ping: false
reported_main_ping: true
reported_new_profile_ping: true
reported_shutdown_ping: true
- client_id: client-4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
- client_id: client-3
sample_id: 30
submission_timestamp: '2023-06-01 11:03:00'
submission_timestamp: '2023-06-01 10:03:00'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- client_id: client-3
sample_id: 30
submission_timestamp: '2023-06-01 10:03:00'
submission_timestamp: '2023-06-01 12:03:00'
environment:
settings:
attribution:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
submission_timestamp_min: '2023-05-28 00:03:00'
attribution:
campaign: campaign2
- client_id: client-3
sample_id: 30
submission_date: '2023-06-01'
submission_timestamp_min: '2023-06-01 00:02:00'
- client_id: client-4
sample_id: 40
submission_date: '2023-06-01'
Expand Down

0 comments on commit 9e9492c

Please sign in to comment.