Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invert join side to user user_profiles as base table #131

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading