Skip to content

Commit c6ee178

Browse files
committed
feat: Use LowCardinality for smaller columns
Generally for columns with less than 10k unique values this provides a noticable performance benefit.
1 parent b043d49 commit c6ee178

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

models/base/xapi_events_all_parsed.sql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
select
1515
event_id as event_id,
16-
JSON_VALUE(event::String, '$.verb.id') as verb_id,
16+
toLowCardinality(JSON_VALUE(event::String, '$.verb.id')) as verb_id,
1717
COALESCE(
1818
NULLIF(JSON_VALUE(event::String, '$.actor.account.name'), ''),
1919
NULLIF(JSON_VALUE(event::String, '$.actor.mbox'), ''),
@@ -23,7 +23,7 @@ select
2323
-- If the contextActivities parent is a course, use that. It can be a "course"
2424
-- type, or a "cmi.interaction" type for multiple question problem submissions.
2525
-- Otherwise use the object id for the course id.
26-
multiIf(
26+
toLowCardinality(multiIf(
2727
-- If the contextActivities parent is a course, use that
2828
JSON_VALUE(
2929
event::String, '$.context.contextActivities.parent[0].definition.type'
@@ -37,10 +37,11 @@ select
3737
JSON_VALUE(event::String, '$.context.contextActivities.grouping[0].id'),
3838
-- Otherwise use the object id
3939
JSON_VALUE(event::String, '$.object.id')
40-
) as course_id,
41-
coalesce(
40+
)) as course_id,
41+
toLowCardinality(splitByString('/', course_id)[-1]) as course_key,
42+
toLowCardinality(coalesce(
4243
get_org_from_course_url(course_id), get_org_from_ccx_course_url(course_id), ''
43-
) as org,
44+
)) as org,
4445
emission_time as emission_time,
4546
event::String as event
4647
from {{ source("xapi", "xapi_events_all") }}

models/completion/completion_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ select
1515
CAST(emission_time, 'DateTime') as emission_time,
1616
actor_id,
1717
object_id,
18-
splitByString('/', course_id)[-1] as course_key,
18+
course_key,
1919
org,
2020
verb_id,
2121
JSON_VALUE(

models/enrollment/enrollment_events.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ select
1515
cast(emission_time as DateTime) as emission_time,
1616
actor_id,
1717
object_id,
18-
splitByString('/', course_id)[-1] as course_key,
18+
course_key,
1919
org,
2020
verb_id,
21-
JSON_VALUE(
21+
toLowCardinality(JSON_VALUE(
2222
event,
2323
'$.object.definition.extensions."https://w3id.org/xapi/acrossx/extensions/type"'
24-
) as enrollment_mode
24+
)) as enrollment_mode
2525
from {{ ref("xapi_events_all_parsed") }}
2626
where
2727
verb_id in (

models/forum/forum_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ select
1414
event_id,
1515
CAST(emission_time, 'DateTime') as emission_time,
1616
org,
17-
splitByString('/', course_id)[-1] as course_key,
17+
course_key,
1818
object_id,
1919
actor_id,
2020
verb_id

models/grading/grading_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ select
1616
CAST(emission_time, 'DateTime') as emission_time,
1717
actor_id,
1818
object_id,
19-
splitByString('/', course_id)[-1] as course_key,
19+
course_key,
2020
org,
2121
verb_id,
2222
JSONExtractFloat(event, 'result', 'score', 'scaled') as scaled_score

models/navigation/navigation_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ select
1515
cast(emission_time as DateTime) as emission_time,
1616
actor_id,
1717
splitByString('/xblock/', object_id)[-1] as block_id,
18-
splitByString('/', course_id)[-1] as course_key,
18+
course_key,
1919
org,
2020
verb_id,
2121
JSONExtractString(event, 'object', 'definition', 'type') as object_type,

models/problems/problem_events.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ select
1515
cast(emission_time as DateTime) as emission_time,
1616
actor_id,
1717
object_id,
18-
splitByString('/', course_id)[-1] as course_key,
18+
course_key,
1919
org,
2020
verb_id,
2121
JSON_VALUE(event, '$.result.response') as responses,
@@ -25,7 +25,7 @@ select
2525
cast(JSON_VALUE(event, '$.result.success') as Bool),
2626
false
2727
) as success,
28-
JSON_VALUE(event, '$.object.definition.interactionType') as interaction_type,
28+
toLowCardinality(JSON_VALUE(event, '$.object.definition.interactionType')) as interaction_type,
2929
if(
3030
verb_id = 'https://w3id.org/xapi/acrossx/verbs/evaluated',
3131
cast(

models/video/video_playback_events.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ select
1515
CAST(emission_time, 'DateTime') as emission_time,
1616
actor_id,
1717
object_id,
18-
splitByString('/', course_id)[-1] as course_key,
18+
course_key,
1919
org,
2020
verb_id,
2121
ceil(

models/video/video_transcript_events.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ select
1414
event_id,
1515
CAST(emission_time, 'DateTime') as emission_time,
1616
org,
17-
splitByString('/', course_id)[-1] as course_key,
17+
course_key,
1818
splitByString('/xblock/', object_id)[2] as video_id,
1919
actor_id,
2020
JSONExtractBool(
@@ -25,7 +25,7 @@ select
2525
) as cc_enabled
2626
from {{ ref("xapi_events_all_parsed") }}
2727
where
28-
verb_id in ('http://adlnet.gov/expapi/verbs/interacted')
28+
verb_id = 'http://adlnet.gov/expapi/verbs/interacted'
2929
and JSONHas(
3030
event,
3131
'result',

0 commit comments

Comments
 (0)