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
  • Loading branch information
ANich committed Nov 8, 2023
1 parent bfbae90 commit f0e8f3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 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
@@ -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

0 comments on commit f0e8f3b

Please sign in to comment.