From b01edb6b621e4bf5ff37e1b8dc92e9544bda0e6a Mon Sep 17 00:00:00 2001 From: Felipe Bermudez Date: Wed, 4 Sep 2024 20:05:06 +0200 Subject: [PATCH] feat: add course_licensing model. --- .../institution_administrators_count.sql | 23 +++++++++++++++++++ models/course_licensing/schema.yml | 12 ++++++++++ models/course_licensing/sources.yml | 20 ++++++++++++++++ packages.yml | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 models/course_licensing/institution_administrators_count.sql create mode 100644 models/course_licensing/schema.yml create mode 100644 models/course_licensing/sources.yml diff --git a/models/course_licensing/institution_administrators_count.sql b/models/course_licensing/institution_administrators_count.sql new file mode 100644 index 0000000..7d39ed3 --- /dev/null +++ b/models/course_licensing/institution_administrators_count.sql @@ -0,0 +1,23 @@ +{{ + config( + materialized="materialized_view", + schema=env_var("ASPECTS_EVENT_SINK_DATABASE", "event_sink"), + post_hook="OPTIMIZE TABLE {{ this }} {{ on_cluster }} FINAL" + ) +}} + +SELECT + institution_id, + count(id) as institution_administrator_count +FROM {{ source("event_sink", "course_licensing_institution_administrator") }} institution_administrator +JOIN + ( + SELECT + id, + max(time_last_dumped) as max_time_last_dumped + FROM {{ source("event_sink", "course_licensing_institution_administrator") }} + GROUP BY id + ) latest_institution_administrators + ON institution_administrator.id = latest_institution_administrators.id + AND institution_administrator.time_last_dumped = latest_institution_administrators.max_time_last_dumped +GROUP BY institution_id diff --git a/models/course_licensing/schema.yml b/models/course_licensing/schema.yml new file mode 100644 index 0000000..a1c1d98 --- /dev/null +++ b/models/course_licensing/schema.yml @@ -0,0 +1,12 @@ +version: 2 + +models: + - name: institution_administrators_count + description: "Count of institution administrators by institution." + columns: + - name: institution_id + data_type: Int32 + description: "Id of the institution." + - name: institution_administrator_count + data_type: Int32 + description: "Count of institution administrators for each institution." diff --git a/models/course_licensing/sources.yml b/models/course_licensing/sources.yml new file mode 100644 index 0000000..49263bd --- /dev/null +++ b/models/course_licensing/sources.yml @@ -0,0 +1,20 @@ +version: 2 + +sources: + - name: event_sink + database: "{{ env_var('ASPECTS_EVENT_SINK_DATABASE', 'event_sink')}}" + tables: + + - name: course_licensing_institution_administrator + columns: + - name: dump_id + - name: time_last_dumped + - name: id + - name: created + - name: modified + - name: institution_id + - name: institution_name + - name: user_id + - name: user_name + - name: user_email + - name: active diff --git a/packages.yml b/packages.yml index 3c77941..c4a0422 100644 --- a/packages.yml +++ b/packages.yml @@ -1,3 +1,3 @@ packages: - git: "https://github.com/openedx/aspects-dbt.git" - revision: cag/course-block-perf + revision: v3.30.0