Skip to content

Commit

Permalink
Merge pull request #131 from openedx/cag/coalesce-actor-id
Browse files Browse the repository at this point in the history
fix: invert join side to user user_profiles as base table
  • Loading branch information
Cristhian Garcia authored Nov 1, 2024
2 parents 4139d69 + 69ff4c1 commit 6e53552
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions models/users/user_pii.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schema=env_var("ASPECTS_EVENT_SINK_DATABASE", "event_sink"),
fields=[
("user_id", "Int32"),
("external_user_id", "UUID"),
("external_user_id", "String"),
("username", "String"),
("name", "String"),
("email", "String"),
Expand All @@ -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
) as external_user_id,
up.username as username,
up.name as name,
up.email as 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 6e53552

Please sign in to comment.