fix comments
This commit is contained in:
@@ -8,11 +8,11 @@
|
|||||||
select
|
select
|
||||||
user_id,
|
user_id,
|
||||||
toDecimal64OrNull(balance, 2) as balance,
|
toDecimal64OrNull(balance, 2) as balance,
|
||||||
toTimeDate64OrNull(created_at, 3) as created_at
|
toDateTime64OrNull(created_at, 3) as created_at
|
||||||
from raw_data
|
from raw_data
|
||||||
where
|
where
|
||||||
toDecimal64OrNull(balance, 2) is not null and
|
toDecimal64OrNull(balance, 2) is not null and
|
||||||
toTimeDate64OrNull(created_at, 3) is not null
|
toDateTime64OrNull(created_at, 3) is not null
|
||||||
|
|
||||||
-- task 2 (failed)
|
-- task 2 (failed)
|
||||||
CREATE TABLE events (
|
CREATE TABLE events (
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
select
|
select
|
||||||
event_id,
|
event_id,
|
||||||
toStartOfHour(toDateTimeOrNull(concatWithSeparator(' ', events_date, events_time)))
|
toStartOfHour(toDateTimeOrNull(concatWithSeparator(' ', event_date, event_time)))
|
||||||
from events
|
from events
|
||||||
where
|
where
|
||||||
toDateOrNull(event_date) is not null and toTimeOrNull(event_time) is not null
|
toDateOrNull(event_date) is not null and toTimeOrNull(event_time) is not null
|
||||||
@@ -57,5 +57,5 @@
|
|||||||
avg(value) as avg_value
|
avg(value) as avg_value
|
||||||
from sensor_data
|
from sensor_data
|
||||||
where
|
where
|
||||||
toDecimal64OrNull(value, 2) is not null
|
value is not null
|
||||||
group by status
|
group by status
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
'/clickhouse/tables/{shard}/mdrozdov/orders',
|
'/clickhouse/tables/{shard}/mdrozdov/orders',
|
||||||
'{replica}'
|
'{replica}'
|
||||||
)
|
)
|
||||||
order by size
|
order by (symbol, time)
|
||||||
|
|
||||||
insert into mdrozdov.orders values
|
insert into mdrozdov.orders values
|
||||||
('2025-07-17 10:00:30', 'AAPL', 50),
|
('2025-07-17 10:00:30', 'AAPL', 50),
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
bl.user_id,
|
bl.user_id,
|
||||||
u.name,
|
u.name,
|
||||||
bl.event_time,
|
bl.event_time,
|
||||||
bl.event_type,
|
bl.event_type
|
||||||
from big_logs bl
|
from big_logs bl
|
||||||
any left join users u
|
any left join users u
|
||||||
using(user_id)
|
using(user_id)
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
Order by id;
|
Order by id;
|
||||||
|
|
||||||
-- region_sales table
|
-- region_sales table
|
||||||
create table region_sales(
|
create table mdrozdov.region_sales(
|
||||||
region String,
|
region String,
|
||||||
date Date,
|
date Date,
|
||||||
sales UInt64
|
sales UInt64
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
CREATE TABLE users (
|
CREATE TABLE mdrozdov.users (
|
||||||
user_id Int,
|
user_id Int,
|
||||||
name String,
|
name String,
|
||||||
age Int,
|
age Int,
|
||||||
@@ -113,10 +113,10 @@ CREATE TABLE users (
|
|||||||
from mdrozdov.events
|
from mdrozdov.events
|
||||||
--3) да, поддерживается, но не обязательно для коммулятивного суммирования строк
|
--3) да, поддерживается, но не обязательно для коммулятивного суммирования строк
|
||||||
--4-6) Сделай WITH recent_events AS (...) — все события за последние 24 часа.
|
--4-6) Сделай WITH recent_events AS (...) — все события за последние 24 часа.
|
||||||
with recent_events AS (
|
with mdrozdov.recent_events AS (
|
||||||
select *
|
select *
|
||||||
from mdrozdov.events
|
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 (
|
), category_list as (
|
||||||
select 'click' as event_type, 'interaction' as category
|
select 'click' as event_type, 'interaction' as category
|
||||||
union all
|
union all
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ engine = ReplicatedMergeTree(
|
|||||||
order by id
|
order by id
|
||||||
|
|
||||||
alter table mdrozdov.clicks
|
alter table mdrozdov.clicks
|
||||||
add index idx_country type set(100) GRANULARITY 2
|
add index idx_country country type set(100) GRANULARITY 2
|
||||||
|
|
||||||
Explain
|
Explain
|
||||||
select *
|
select *
|
||||||
@@ -59,7 +59,7 @@ engine = ReplicatedMergeTree(
|
|||||||
)
|
)
|
||||||
order by id
|
order by id
|
||||||
|
|
||||||
ALTER TABLE users
|
ALTER TABLE mdrozdov.users
|
||||||
ADD INDEX idx_email email TYPE bloom_filter(0.01) GRANULARITY 2;
|
ADD INDEX idx_email email TYPE bloom_filter(0.01) GRANULARITY 2;
|
||||||
|
|
||||||
SELECT * FROM users WHERE email = 'alice@mail.com';
|
SELECT * FROM mdrozdov.users WHERE email = 'alice@mail.com';
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
--task 3
|
--task 3
|
||||||
CREATE MATERIALIZED VIEW
|
CREATE MATERIALIZED VIEW
|
||||||
|
to
|
||||||
ENGINE = SummingMergeTree
|
ENGINE = SummingMergeTree
|
||||||
order by date
|
order by date
|
||||||
mv_clicks_per_day AS
|
mv_clicks_per_day AS
|
||||||
@@ -30,4 +31,4 @@
|
|||||||
toDate(event_time) as date,
|
toDate(event_time) as date,
|
||||||
count(*) as total_clicks
|
count(*) as total_clicks
|
||||||
from raw_events
|
from raw_events
|
||||||
group date
|
group by date
|
||||||
@@ -76,14 +76,6 @@
|
|||||||
course_id::INT
|
course_id::INT
|
||||||
FROM raw.lessons;
|
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)
|
insert into core.fact_lesson_views (user_id, lesson_id, course_id, viewed_at)
|
||||||
select
|
select
|
||||||
@@ -94,16 +86,7 @@
|
|||||||
from raw.lessons_views lw
|
from raw.lessons_views lw
|
||||||
join raw.lessons l on lw.lesson_id = l.id;
|
join raw.lessons l on lw.lesson_id = l.id;
|
||||||
|
|
||||||
insert into core.enrollments (user_id, lesson_id, course_id, viewed_at)
|
insert into core.enrollments (user_id, course_id, enrolled_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)
|
|
||||||
select
|
select
|
||||||
user_id,
|
user_id,
|
||||||
course_id,
|
course_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user