Skip to content

Commit

Permalink
fix: invert join side to user user_profiles as base table
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 31, 2024
1 parent 4139d69 commit cee1b65
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions models/users/user_pii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ with
from {{ source("event_sink", "user_profile") }}
group by user_id
)
select ex.user_id as user_id, ex.external_user_id, ex.username, up.name, up.email
from {{ source("event_sink", "external_id") }} ex
left outer join most_recent_user_profile mrup on mrup.user_id = ex.user_id
select
ex.user_id as user_id,
if(
empty(ex.external_user_id),
concat('mailto:', email),
ex.external_user_id::String
),
ex.username,
up.name,
up.email
from most_recent_user_profile mrup
left outer join
{{ source("event_sink", "external_id") }} ex on mrup.user_id = ex.user_id
left outer join
{{ source("event_sink", "user_profile") }} up
on up.user_id = mrup.user_id
Expand Down

0 comments on commit cee1b65

Please sign in to comment.