Skip to content

Commit

Permalink
feat: add MV for transcript usage
Browse files Browse the repository at this point in the history
This update creates a new materialized view for transcript
enabled/disabled events and updates `fact_transcript_usage` to use this
new MV. This should improve the performance of transcript-related charts
in Superset by avoiding relying on the base `xapi_events_all_parsed` table.
  • Loading branch information
SoryRawyer committed Dec 18, 2023
1 parent d74b350 commit 47857ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
18 changes: 3 additions & 15 deletions models/video/fact_transcript_usage.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
with transcripts as (
select
emission_time,
org,
splitByString('/', course_id)[-1] as course_key,
splitByString('/xblock/', object_id)[2] as video_id,
actor_id
from
{{ ref('xapi_events_all_parsed') }}
where
verb_id = 'http://adlnet.gov/expapi/verbs/interacted'
and JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/video/extensions/cc-enabled"') = 'true'
)

select
transcripts.emission_time as emission_time,
transcripts.org as org,
Expand All @@ -23,7 +9,9 @@ select
blocks.display_name_with_location as video_name_with_location,
transcripts.actor_id as actor_id
from
transcripts
{{ ref('video_transcript_events') }} transcripts
join {{ ref('dim_course_blocks')}} blocks
on (transcripts.course_key = blocks.course_key
and transcripts.video_id = blocks.block_id)
where
transcripts.cc_enabled
19 changes: 19 additions & 0 deletions models/video/video_transcript_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ config(
materialized='materialized_view',
engine='MergeTree()',
primary_key='(org, course_key, video_id)',
order_by='(org, course_key, video_id, emission_time, actor_id, cc_enabled, event_id)'
) }}

SELECT
event_id,
CAST(emission_time, 'DateTime') AS emission_time,
org,
splitByString('/', course_id)[-1] AS course_key,
splitByString('/xblock/', object_id)[2] as video_id,
actor_id,
JSONExtractBool(event_str, 'result','extensions','https://w3id.org/xapi/video/extensions/cc-enabled') as cc_enabled
FROM {{ ref('xapi_events_all_parsed') }}
WHERE
verb_id IN ('http://adlnet.gov/expapi/verbs/interacted')
AND JSONHas(event_str, 'result', 'extensions', 'https://w3id.org/xapi/video/extensions/cc-enabled')

0 comments on commit 47857ad

Please sign in to comment.