Skip to content

Commit

Permalink
Merge pull request #42 from openedx/cag/partition-tables
Browse files Browse the repository at this point in the history
feat: partition all tables by year and month
  • Loading branch information
Ian2012 authored Jan 30, 2024
2 parents 04939b5 + 00ff908 commit 3897b09
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions models/base/xapi_events_all_parsed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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)',
partition_by='(toYYYYMM(emission_time))',
post_hook='OPTIMIZE TABLE {{ this }} {{ on_cluster() }} FINAL'
) }}

Expand Down
3 changes: 2 additions & 1 deletion models/completion/completion_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
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)'
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/enrollment/enrollment_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
engine=get_engine('ReplacingMergeTree()'),
primary_key='(org, course_key)',
order_by='(org, course_key, emission_time, actor_id, enrollment_mode, event_id)'
order_by='(org, course_key, emission_time, actor_id, enrollment_mode, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/forum/forum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
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)'
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/grading/grading_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
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)'
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, scaled_score, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}


Expand Down
3 changes: 2 additions & 1 deletion models/navigation/navigation_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
engine=get_engine('ReplacingMergeTree()'),
primary_key='(org, course_key, object_type)',
order_by='(org, course_key, object_type, emission_time, actor_id, starting_position, event_id)'
order_by='(org, course_key, object_type, emission_time, actor_id, starting_position, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/problems/problem_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
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)'
order_by='(org, course_key, verb_id, emission_time, actor_id, object_id, responses, success, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/video/video_playback_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
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)'
order_by='(org, course_key, verb_id, emission_time, actor_id, video_position, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down
3 changes: 2 additions & 1 deletion models/video/video_transcript_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
schema=env_var('ASPECTS_XAPI_DATABASE', 'xapi'),
engine=get_engine('ReplacingMergeTree()'),
primary_key='(org, course_key, video_id)',
order_by='(org, course_key, video_id, emission_time, actor_id, cc_enabled, event_id)'
order_by='(org, course_key, video_id, emission_time, actor_id, cc_enabled, event_id)',
partition_by='(toYYYYMM(emission_time))',
) }}

SELECT
Expand Down

0 comments on commit 3897b09

Please sign in to comment.