full solve, but still dont work
This commit is contained in:
@@ -1,51 +1,51 @@
|
||||
--lesson_popularity_summary data mart
|
||||
create table mdrozdov.dm_lesson_popularity_summary
|
||||
ON CLUSTER clickhouse_cluster(
|
||||
lesson_id UInt32,
|
||||
lesson_id Int32,
|
||||
lesson_title String,
|
||||
course_id UInt32,
|
||||
course_id Int32,
|
||||
course_title String,
|
||||
total_views AggregateFunction(count, UInt64),
|
||||
unique_users AggregateFunction(uniqExact, Int32),
|
||||
first_view AggregateFunction(min, DateTime),
|
||||
last_view AggregateFunction(max, DateTime)
|
||||
total_views Int32,
|
||||
unique_users Int32,
|
||||
first_view DateTime64(3),
|
||||
last_view DateTime64(3)
|
||||
)
|
||||
ENGINE = ReplicatedAggregatingMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/dm_lesson_popularity_summary',
|
||||
'{replica}'
|
||||
ENGINE = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/dm_lesson_popularity_summary1',
|
||||
'{replica}'
|
||||
)
|
||||
ORDER BY (lesson_id, course_id);
|
||||
|
||||
create materialized view mdrozdov.lesson_popularity_summary to mdrozdov.dm_lesson_popularity_summary as
|
||||
create materialized view mdrozdov.lesson_popularity_summary
|
||||
to mdrozdov.dm_lesson_popularity_summary as
|
||||
select
|
||||
dl.lesson_id as lesson_id,
|
||||
dl.title as lesson_title,
|
||||
dl.course_id as course_id,
|
||||
dc.title as course_title,
|
||||
countState(flv.lesson_id) as total_views,
|
||||
uniqExactState(flv.user_id) as unique_users,
|
||||
minState(toDateTime(flv.viewed_at)) as first_view,
|
||||
maxState(toDateTime(flv.viewed_at)) as last_view
|
||||
dl.lesson_id as lesson_id,
|
||||
dl.title as lesson_title,
|
||||
dl.course_id as course_id,
|
||||
dc.title as course_title,
|
||||
count(flv.lesson_id) as total_views,
|
||||
count(distinct flv.user_id) as unique_users,
|
||||
min(flv.viewed_at) as first_view,
|
||||
max(flv.viewed_at) as last_view
|
||||
from mdrozdov.core_fact_lesson_views flv
|
||||
right join mdrozdov.core_dim_course dc
|
||||
on flv.course_id = dc.course_id
|
||||
left join mdrozdov.core_dim_lesson dl
|
||||
on dl.lesson_id = flv.lesson_id
|
||||
left join mdrozdov.core_dim_course dc
|
||||
on flv.course_id = dc.course_id
|
||||
group by dl.lesson_id, dl.title, dl.course_id, dc.title
|
||||
|
||||
|
||||
--inactive_users_summary
|
||||
create table mdrozdov.dm_inactive_users_summary
|
||||
ON CLUSTER clickhouse_cluster(
|
||||
user_id Int32,
|
||||
name String,
|
||||
email Nullable(String),
|
||||
email String,
|
||||
age Int32,
|
||||
registered_courses_count AggregateFunction(uniqExact, Int32),
|
||||
registered_courses_count Int32,
|
||||
registration_date Date
|
||||
)
|
||||
ENGINE = ReplicatedAggregatingMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/dm_inactive_users_summary',
|
||||
ENGINE = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/dm_inactive_users_summary1',
|
||||
'{replica}'
|
||||
)
|
||||
ORDER BY user_id
|
||||
@@ -54,12 +54,12 @@ create materialized view mdrozdov.inactive_users_summary
|
||||
to mdrozdov.dm_inactive_users_summary
|
||||
as
|
||||
select
|
||||
du.user_id as user_id,
|
||||
du.name as name,
|
||||
du.email as email,
|
||||
du.age as age,
|
||||
uniqExactState(e.course_id) as registered_courses_count,
|
||||
du.registration_date
|
||||
du.user_id as user_id,
|
||||
du.name as name,
|
||||
du.email as email,
|
||||
du.age as age,
|
||||
count(e.course_id) as registered_courses_count,
|
||||
du.registration_date as registration_date
|
||||
from mdrozdov.core_fact_lesson_views flv
|
||||
right join mdrozdov.core_dim_user du
|
||||
on du.user_id = flv.user_id
|
||||
@@ -75,11 +75,11 @@ ON CLUSTER clickhouse_cluster(
|
||||
user_name String,
|
||||
course_id Int32,
|
||||
course_title String,
|
||||
lessons_in_course AggregateFunction(count, UInt64),
|
||||
lessons_viewed AggregateFunction(count, UInt64),
|
||||
lessons_in_course Int32,
|
||||
lessons_viewed Int32,
|
||||
completion_rate Decimal(4, 3)
|
||||
)
|
||||
ENGINE = ReplicatedAggregatingMergeTree(
|
||||
ENGINE = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/dm_course_completion_rate',
|
||||
'{replica}'
|
||||
)
|
||||
@@ -91,14 +91,14 @@ create materialized view mdrozdov.course_completion_rate
|
||||
select
|
||||
course_id,
|
||||
count(*) as lessons_in_course
|
||||
from core.dim_lesson
|
||||
from mdrozdov.core_dim_lesson
|
||||
group by course_id
|
||||
), lessons_viewed as (
|
||||
select
|
||||
user_id,
|
||||
course_id,
|
||||
count(*) as lessons_viewed
|
||||
from fact_lesson_views flv
|
||||
from mdrozdov.core_fact_lesson_views flv
|
||||
group by user_id, course_id
|
||||
)
|
||||
select
|
||||
@@ -120,4 +120,16 @@ create materialized view mdrozdov.course_completion_rate
|
||||
join mdrozdov.core_dim_course dc
|
||||
on e.course_id = dc.course_id
|
||||
left join lessons_viewed lv
|
||||
on du.user_id = lv.user_id and dc.course_id = lv.course_id
|
||||
on du.user_id = lv.user_id and dc.course_id = lv.course_id
|
||||
|
||||
--данные из-за несовпадения названий столбцов в импорте/экспорте пришлось удалять, короче проще вручную
|
||||
-- их добавить
|
||||
insert into mdrozdov.core_fact_lesson_views(user_id, lesson_id, course_id, viewed_at) values
|
||||
(1, 1, 1, '2023-01-16 10:00:00'),
|
||||
(1, 2, 1, '2023-01-16 10:15:00'),
|
||||
(2, 1, 1, '2023-01-21 09:00:00'),
|
||||
(3, 3, 2, '2023-03-06 12:00:00'),
|
||||
(4, 4, 3, '2023-04-02 10:00:00'),
|
||||
(4, 5, 3, '2023-04-03 10:00:00')
|
||||
|
||||
-- данные в mdrozdov.core_enrollments загружал через импорт
|
||||
Reference in New Issue
Block a user