From cee1b6577fff6c5f24baeb38252c467d245d4d98 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 31 Oct 2024 10:28:30 -0500 Subject: [PATCH 1/4] fix: invert join side to user user_profiles as base table --- models/users/user_pii.sql | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/models/users/user_pii.sql b/models/users/user_pii.sql index a9ce7147..c36ade43 100644 --- a/models/users/user_pii.sql +++ b/models/users/user_pii.sql @@ -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 From a11e9816150ea415a6611a567c6abb306e2f0ab6 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 31 Oct 2024 10:30:10 -0500 Subject: [PATCH 2/4] fix: invert join side to user user_profiles as base table --- models/users/user_pii.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/users/user_pii.sql b/models/users/user_pii.sql index c36ade43..1c9a5dbb 100644 --- a/models/users/user_pii.sql +++ b/models/users/user_pii.sql @@ -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"), From e6c234459124776cd32afae9b86dbb5e050b640d Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 31 Oct 2024 10:52:48 -0500 Subject: [PATCH 3/4] fix: invert join side to user user_profiles as base table --- models/users/user_pii.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/users/user_pii.sql b/models/users/user_pii.sql index 1c9a5dbb..8746a4c3 100644 --- a/models/users/user_pii.sql +++ b/models/users/user_pii.sql @@ -31,8 +31,8 @@ select empty(ex.external_user_id), concat('mailto:', email), ex.external_user_id::String - ), - ex.username, + ) as external_user_id, + up.username, up.name, up.email from most_recent_user_profile mrup From 69ff4c18cdaa0a1a5b6e3f81eef050e1ddd0503a Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 31 Oct 2024 13:58:16 -0500 Subject: [PATCH 4/4] fix: use alias for column names --- models/users/user_pii.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/users/user_pii.sql b/models/users/user_pii.sql index 8746a4c3..2999f8b5 100644 --- a/models/users/user_pii.sql +++ b/models/users/user_pii.sql @@ -32,9 +32,9 @@ select concat('mailto:', email), ex.external_user_id::String ) as external_user_id, - up.username, - up.name, - up.email + 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