From 0433c728282ca3f381a92aadda765cf9cf2f1402 Mon Sep 17 00:00:00 2001 From: dr0zd Date: Sat, 31 Jan 2026 03:29:26 +0700 Subject: [PATCH] fix comments --- mdrozdov/clickhouse/data_types.sql | 8 ++++---- mdrozdov/clickhouse/joins.sql | 4 ++-- mdrozdov/clickhouse/merge_tree_family.sql | 2 +- mdrozdov/clickhouse/queries.sql | 6 +++--- mdrozdov/clickhouse/secondary_index.sql | 6 +++--- mdrozdov/clickhouse/view_distribute.sql | 3 ++- mdrozdov/greenplum/core_layer.sql | 19 +------------------ 7 files changed, 16 insertions(+), 32 deletions(-) diff --git a/mdrozdov/clickhouse/data_types.sql b/mdrozdov/clickhouse/data_types.sql index c7089fb..fc580c3 100644 --- a/mdrozdov/clickhouse/data_types.sql +++ b/mdrozdov/clickhouse/data_types.sql @@ -8,11 +8,11 @@ select user_id, toDecimal64OrNull(balance, 2) as balance, - toTimeDate64OrNull(created_at, 3) as created_at + toDateTime64OrNull(created_at, 3) as created_at from raw_data where toDecimal64OrNull(balance, 2) is not null and - toTimeDate64OrNull(created_at, 3) is not null + toDateTime64OrNull(created_at, 3) is not null -- task 2 (failed) CREATE TABLE events ( @@ -23,7 +23,7 @@ select event_id, - toStartOfHour(toDateTimeOrNull(concatWithSeparator(' ', events_date, events_time))) + toStartOfHour(toDateTimeOrNull(concatWithSeparator(' ', event_date, event_time))) from events where toDateOrNull(event_date) is not null and toTimeOrNull(event_time) is not null @@ -57,5 +57,5 @@ avg(value) as avg_value from sensor_data where - toDecimal64OrNull(value, 2) is not null + value is not null group by status \ No newline at end of file diff --git a/mdrozdov/clickhouse/joins.sql b/mdrozdov/clickhouse/joins.sql index 9b797cb..4701740 100644 --- a/mdrozdov/clickhouse/joins.sql +++ b/mdrozdov/clickhouse/joins.sql @@ -65,7 +65,7 @@ '/clickhouse/tables/{shard}/mdrozdov/orders', '{replica}' ) - order by size + order by (symbol, time) insert into mdrozdov.orders values ('2025-07-17 10:00:30', 'AAPL', 50), @@ -97,7 +97,7 @@ bl.user_id, u.name, bl.event_time, - bl.event_type, + bl.event_type from big_logs bl any left join users u using(user_id) \ No newline at end of file diff --git a/mdrozdov/clickhouse/merge_tree_family.sql b/mdrozdov/clickhouse/merge_tree_family.sql index 71db981..74dbfba 100644 --- a/mdrozdov/clickhouse/merge_tree_family.sql +++ b/mdrozdov/clickhouse/merge_tree_family.sql @@ -18,7 +18,7 @@ Order by id; -- region_sales table - create table region_sales( + create table mdrozdov.region_sales( region String, date Date, sales UInt64 diff --git a/mdrozdov/clickhouse/queries.sql b/mdrozdov/clickhouse/queries.sql index 572ace7..e2d7afe 100644 --- a/mdrozdov/clickhouse/queries.sql +++ b/mdrozdov/clickhouse/queries.sql @@ -1,4 +1,4 @@ -CREATE TABLE users ( +CREATE TABLE mdrozdov.users ( user_id Int, name String, age Int, @@ -113,10 +113,10 @@ CREATE TABLE users ( from mdrozdov.events --3) да, поддерживается, но не обязательно для коммулятивного суммирования строк --4-6) Сделай WITH recent_events AS (...) — все события за последние 24 часа. - with recent_events AS ( + with mdrozdov.recent_events AS ( select * from mdrozdov.events - where event_time >= '2025-07-18'::DATE - interval '1 day' + where event_time >= toDateTime('2025-07-18') - interval 1 day ), category_list as ( select 'click' as event_type, 'interaction' as category union all diff --git a/mdrozdov/clickhouse/secondary_index.sql b/mdrozdov/clickhouse/secondary_index.sql index 3a902d7..53f172c 100644 --- a/mdrozdov/clickhouse/secondary_index.sql +++ b/mdrozdov/clickhouse/secondary_index.sql @@ -40,7 +40,7 @@ engine = ReplicatedMergeTree( order by id alter table mdrozdov.clicks -add index idx_country type set(100) GRANULARITY 2 +add index idx_country country type set(100) GRANULARITY 2 Explain select * @@ -59,7 +59,7 @@ engine = ReplicatedMergeTree( ) order by id -ALTER TABLE users +ALTER TABLE mdrozdov.users ADD INDEX idx_email email TYPE bloom_filter(0.01) GRANULARITY 2; -SELECT * FROM users WHERE email = 'alice@mail.com'; \ No newline at end of file +SELECT * FROM mdrozdov.users WHERE email = 'alice@mail.com'; \ No newline at end of file diff --git a/mdrozdov/clickhouse/view_distribute.sql b/mdrozdov/clickhouse/view_distribute.sql index d330749..41ed079 100644 --- a/mdrozdov/clickhouse/view_distribute.sql +++ b/mdrozdov/clickhouse/view_distribute.sql @@ -23,6 +23,7 @@ --task 3 CREATE MATERIALIZED VIEW + to ENGINE = SummingMergeTree order by date mv_clicks_per_day AS @@ -30,4 +31,4 @@ toDate(event_time) as date, count(*) as total_clicks from raw_events - group date \ No newline at end of file + group by date \ No newline at end of file diff --git a/mdrozdov/greenplum/core_layer.sql b/mdrozdov/greenplum/core_layer.sql index 557e771..8ff3a53 100644 --- a/mdrozdov/greenplum/core_layer.sql +++ b/mdrozdov/greenplum/core_layer.sql @@ -76,14 +76,6 @@ course_id::INT FROM raw.lessons; - INSERT INTO core.dim_lesson (lesson_id, title, duration_min, course_id) - SELECT DISTINCT - id::INT, - title::TEXT, - duration_min::INT, - course_id::INT - FROM raw.lessons; - -- Заполнение таблицы фактов insert into core.fact_lesson_views (user_id, lesson_id, course_id, viewed_at) select @@ -94,16 +86,7 @@ from raw.lessons_views lw join raw.lessons l on lw.lesson_id = l.id; - insert into core.enrollments (user_id, lesson_id, course_id, viewed_at) - select - lw.user_id, - lw.lesson_id, - l.course_id, - lw.viewed_at - from raw.lessons_views lw - join raw.lessons l on lw.lesson_id = l.id; - - insert into enrollments (user_id, course_id, enrolled_at) + insert into core.enrollments (user_id, course_id, enrolled_at) select user_id, course_id,