-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from SoryRawyer/rds/include-materialized-views
feat: move second-tier MVs into dbt project (FC-0033)
- Loading branch information
Showing
19 changed files
with
193 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- Return an ON CLUSTER clause if we are running dbt against a cluster | ||
{% macro on_cluster() -%} | ||
{%- if env_var("CLICKHOUSE_CLUSTER_NAME", "") != "" -%} | ||
ON CLUSTER {{ env_var("CLICKHOUSE_CLUSTER_NAME") }} | ||
{%- endif -%} | ||
{%- endmacro %} | ||
|
||
-- Return a version of the given table engine suitable for use on ClickHouse clusters | ||
{% macro get_engine(engine) -%} | ||
{%- if env_var("CLICKHOUSE_CLUSTER_NAME", "") != "" -%} | ||
{{ "Replicated" + engine }} | ||
{% else %} | ||
{{ engine }} | ||
{%- endif -%} | ||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_id, verb_id, actor_id, emission_time, event_id)', | ||
order_by='(org, course_id, verb_id, actor_id, emission_time, event_id)', | ||
post_hook='OPTIMIZE TABLE {{ this }} {{ on_cluster() }} FINAL' | ||
) }} | ||
|
||
SELECT | ||
event_id as event_id, | ||
JSON_VALUE(event_str, '$.verb.id') as verb_id, | ||
COALESCE( | ||
NULLIF(JSON_VALUE(event_str, '$.actor.account.name'), ''), | ||
NULLIF(JSON_VALUE(event_str, '$.actor.mbox'), ''), | ||
JSON_VALUE(event_str, '$.actor.mbox_sha1sum') | ||
) as actor_id, | ||
JSON_VALUE(event_str, '$.object.id') as object_id, | ||
-- If the contextActivities parent is a course, use that. Otherwise use the object id for the course id | ||
if( | ||
JSON_VALUE( | ||
event_str, | ||
'$.context.contextActivities.parent[0].definition.type') | ||
= 'http://adlnet.gov/expapi/activities/course', | ||
JSON_VALUE(event_str, '$.context.contextActivities.parent[0].id'), | ||
JSON_VALUE(event_str, '$.object.id') | ||
) as course_id, | ||
coalesce(get_org_from_course_url(course_id), '') as org, | ||
emission_time as emission_time, | ||
event_str as event_str | ||
FROM {{ source('xapi', 'xapi_events_all') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key, verb_id)', | ||
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, event_id)' | ||
) }} | ||
|
||
SELECT | ||
event_id, | ||
CAST(emission_time, 'DateTime') AS emission_time, | ||
actor_id, | ||
object_id, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
org, | ||
verb_id, | ||
JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/cmi5/result/extensions/progress"') AS progress_percent | ||
FROM {{ ref('xapi_events_all_parsed') }} | ||
WHERE verb_id = 'http://adlnet.gov/expapi/verbs/progressed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key)', | ||
order_by='(org, course_key, emission_time, actor_id, enrollment_mode, event_id)' | ||
) }} | ||
|
||
SELECT | ||
event_id, | ||
cast(emission_time as DateTime) as emission_time, | ||
actor_id, | ||
object_id, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
org, | ||
verb_id, | ||
JSON_VALUE(event_str, '$.object.definition.extensions."https://w3id.org/xapi/acrossx/extensions/type"') AS enrollment_mode | ||
FROM {{ ref('xapi_events_all_parsed') }} | ||
WHERE verb_id IN ( | ||
'http://adlnet.gov/expapi/verbs/registered', | ||
'http://id.tincanapi.com/verb/unregistered' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key, verb_id)', | ||
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, event_id)' | ||
) }} | ||
|
||
SELECT | ||
event_id, | ||
CAST(emission_time, 'DateTime') AS emission_time, | ||
org, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
object_id, | ||
actor_id, | ||
verb_id | ||
FROM {{ ref('xapi_events_all_parsed') }} | ||
WHERE JSON_VALUE(event_str, '$.object.definition.type') = 'http://id.tincanapi.com/activitytype/discussion' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key, verb_id)', | ||
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, scaled_score, event_id)' | ||
) }} | ||
|
||
|
||
SELECT | ||
event_id, | ||
CAST(emission_time, 'DateTime') AS emission_time, | ||
actor_id, | ||
object_id, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
org, | ||
verb_id, | ||
JSONExtractFloat(event_str, 'result', 'score', 'scaled') AS scaled_score | ||
FROM {{ ref('xapi_events_all_parsed') }} | ||
WHERE verb_id IN ('http://id.tincanapi.com/verb/earned', 'https://w3id.org/xapi/acrossx/verbs/evaluated') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key, verb_id)', | ||
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, responses, success, event_id)' | ||
) }} | ||
|
||
SELECT | ||
event_id, | ||
cast(emission_time as DateTime) as emission_time, | ||
actor_id, | ||
object_id, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
org, | ||
verb_id, | ||
JSON_VALUE(event_str, '$.result.response') as responses, | ||
JSON_VALUE(event_str, '$.result.score.scaled') as scaled_score, | ||
if( | ||
verb_id = 'https://w3id.org/xapi/acrossx/verbs/evaluated', | ||
cast(JSON_VALUE(event_str, '$.result.success') as Bool), | ||
false | ||
) as success, | ||
JSON_VALUE(event_str, '$.object.definition.interactionType') as interaction_type, | ||
if( | ||
verb_id = 'https://w3id.org/xapi/acrossx/verbs/evaluated', | ||
cast(JSON_VALUE(event_str, '$.object.definition.extensions."http://id.tincanapi.com/extension/attempt-id"') as Int16), | ||
0 | ||
) as attempts | ||
FROM | ||
{{ ref('xapi_events_all_parsed') }} | ||
WHERE | ||
verb_id in ( | ||
'https://w3id.org/xapi/acrossx/verbs/evaluated', | ||
'http://adlnet.gov/expapi/verbs/passed', | ||
'http://adlnet.gov/expapi/verbs/asked' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ config( | ||
materialized='materialized_view', | ||
engine=get_engine('ReplacingMergeTree()'), | ||
primary_key='(org, course_key, verb_id)', | ||
order_by='(org, course_key, verb_id, emission_time, actor_id, video_position, event_id)' | ||
) }} | ||
|
||
SELECT | ||
event_id, | ||
CAST(emission_time, 'DateTime') AS emission_time, | ||
actor_id, | ||
object_id, | ||
splitByString('/', course_id)[-1] AS course_key, | ||
org, | ||
verb_id, | ||
ceil(CAST(coalesce(nullIf(JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/video/extensions/time"'), ''), nullIf(JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/video/extensions/time-from"'), ''), '0.0'), 'Decimal32(2)')) AS video_position | ||
FROM {{ ref('xapi_events_all_parsed') }} | ||
WHERE (verb_id IN ('http://adlnet.gov/expapi/verbs/completed', 'http://adlnet.gov/expapi/verbs/initialized', 'http://adlnet.gov/expapi/verbs/terminated', 'https://w3id.org/xapi/video/verbs/paused', 'https://w3id.org/xapi/video/verbs/played', 'https://w3id.org/xapi/video/verbs/seeked')) AND (object_id LIKE '%video+block%') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dbt-clickhouse==1.4.1 | ||
dbt-core==1.4.0 | ||
dbt-clickhouse==1.7.0 | ||
dbt-core==1.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters