Skip to content

Commit

Permalink
Updated comment and read me file
Browse files Browse the repository at this point in the history
  • Loading branch information
NeerajBassi committed Oct 28, 2024
1 parent 98b83f2 commit 18f56bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ This design is pretty simple with only 3 steps:
### The Cumulation step
- The table schema for this step is [here](tables/active_users_cumulated.sql)
- The query for this step is much more complex. It's [here](queries/active_users_cumulated_populate.sql)
- This step we take **today's** data from the daily table and **yesterday's** data from the cumulated table
- In this step we take **today's** data from the daily table and **yesterday's** data from the cumulated table
- We `FULL OUTER JOIN` these two data sets on `today.user_id = yesterday.user_id`
- If a user is brand new, they won't be in yesterday's data also if a user wasn't active today, they aren't in today's data
- If a user is brand new, they won't be in yesterday's data. Also, if a user wasn't active today, they aren't in today's data
- So we need to `COALESCE(today.user_id, yesterday.user_id) as user_id` to keep track of all the users
- Next we want to build the `activity_array` column. We only want `activity_array` to store the data of the last 30 days
- So we check to see if `CARDINALITY(activity_array) < 30` to understand if we can just add today's value to the front of the array or do we need to slice an element off the end of the array before adding today's value to the front
Expand Down
2 changes: 1 addition & 1 deletion queries/active_users_cumulated_populate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ today AS (
-- is_active_today may be null as well since it's null on days when a user didn't generate an event
combined AS (
SELECT
-- We need to COALESCE here since t.user_id and y.user_id may be
-- We need to COALESCE here since t.user_id may be a new user and it never existed in cumulative table before.
COALESCE(y.user_id, t.user_id) AS user_id,
-- if y.activity_array is null (indicating a brand new user), we have to coalesce with an array of size 1
-- this array just holds the value for today since that's the only history we have
Expand Down

0 comments on commit 18f56bc

Please sign in to comment.