Skip to content

Commit

Permalink
Merge branch 'main' into mvtest
Browse files Browse the repository at this point in the history
  • Loading branch information
saraburns1 authored Nov 7, 2024
2 parents a57cd06 + 6e53552 commit 992d506
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
4 changes: 3 additions & 1 deletion models/enrollment/fact_enrollments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ select
from enrollments
join {{ ref("course_names") }} courses on enrollments.course_key = courses.course_key
left outer join
{{ ref("dim_user_pii") }} users on toUUID(actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (actor_id like 'mailto:%' and SUBSTRING(actor_id, 8) = users.email)
or actor_id = toString(users.external_user_id)
4 changes: 3 additions & 1 deletion models/grading/fact_student_status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ join
on fes.org = courses.org
and fes.course_key = courses.course_key
left outer join
{{ ref("dim_user_pii") }} users on toUUID(actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (actor_id like 'mailto:%' and SUBSTRING(actor_id, 8) = users.email)
or actor_id = toString(users.external_user_id)
4 changes: 3 additions & 1 deletion models/navigation/fact_navigation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ join
and navigation.block_id = blocks.block_id
)
left outer join
{{ ref("dim_user_pii") }} users on toUUID(actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (actor_id like 'mailto:%' and SUBSTRING(actor_id, 8) = users.email)
or actor_id = toString(users.external_user_id)
4 changes: 3 additions & 1 deletion models/navigation/fact_pageview_engagement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ join
and pv.block_id = course_blocks.block_id
)
left outer join
{{ ref("dim_user_pii") }} users on toUUID(pv.actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (pv.actor_id like 'mailto:%' and SUBSTRING(pv.actor_id, 8) = users.email)
or pv.actor_id = toString(users.external_user_id)
4 changes: 3 additions & 1 deletion models/problems/fact_problem_responses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ join
and responses.problem_id = blocks.block_id
)
left outer join
{{ ref("dim_user_pii") }} users on toUUID(actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (actor_id like 'mailto:%' and SUBSTRING(actor_id, 8) = users.email)
or actor_id = toString(users.external_user_id)
group by
-- multi-part questions include an extra record for the response to the first
-- part of the question. this group by clause eliminates the duplicate record
Expand Down
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
4 changes: 3 additions & 1 deletion models/video/fact_video_engagement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ join
and ve.block_id = course_blocks.block_id
)
left outer join
{{ ref("dim_user_pii") }} users on toUUID(ve.actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (ve.actor_id like 'mailto:%' and SUBSTRING(ve.actor_id, 8) = users.email)
or ve.actor_id = toString(users.external_user_id)
4 changes: 3 additions & 1 deletion models/video/fact_video_plays.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ join
{{ ref("dim_course_blocks_extended") }} blocks
on (plays.course_key = blocks.course_key and plays.video_id = blocks.block_id)
left outer join
{{ ref("dim_user_pii") }} users on toUUID(actor_id) = users.external_user_id
{{ ref("dim_user_pii") }} users
on (actor_id like 'mailto:%' and SUBSTRING(actor_id, 8) = users.email)
or actor_id = toString(users.external_user_id)

0 comments on commit 992d506

Please sign in to comment.