diff --git a/dsolovianov/clickhouse/image.png b/dsolovianov/clickhouse/image.png new file mode 100644 index 0000000..7638600 Binary files /dev/null and b/dsolovianov/clickhouse/image.png differ diff --git a/dsolovianov/clickhouse/Типы таблиц - Домашки.sql b/dsolovianov/clickhouse/Типы таблиц - Домашки.sql new file mode 100644 index 0000000..04cda20 --- /dev/null +++ b/dsolovianov/clickhouse/Типы таблиц - Домашки.sql @@ -0,0 +1,72 @@ +--Задача 1: Создай таблицу page_views + +CREATE TABLE page_views ( + user_id UInt64, + url String, + view_time DateTime + ) +ENGINE = MergeTree() +PARTITION BY toYYYYMM(view_time) +ORDER BY (user_id, view_time); + +--Задача 2: Создай таблицу users + +CREATE TABLE users ( +id UInt64, +name String, +updated_at DateTime + ) +ENGINE = ReplacingMergeTree(updated_at) +ORDER BY id; + +-- Задача 3: Создай таблицу region_sales + +CREATE TABLE region_sales ( +region String, +date Date, +sales UInt64 + ) +ENGINE = SummingMergeTree() +PARTITION BY toYYYYMM(date) +ORDER BY (region, date); + +--Задача 4.1: Создай таблицу user_metrics + +CREATE TABLE user_metrics ( +region String, +avg_age_state AggregateFunction(avg, UInt8), +active_users_state AggregateFunction(uniq, UInt64) + ) +ENGINE = AggregatingMergeTree() +ORDER BY region; + +--Задача 4.3: - Вставь данные и Читай их через `avgMerge()` и `uniqMerge()` + +INSERT INTO user_metrics +SELECT + region, + avgState(age) AS avg_age_state, + uniqState(toUInt64(user_id)) AS active_users_state +FROM +( + SELECT 'Samara' AS region, 25 AS age, 1 AS user_id + UNION ALL + SELECT 'Moscow', 30, 2 + UNION ALL + SELECT 'Moscow', 22, 3 + UNION ALL + SELECT 'Samara', 22, 4 + UNION ALL + SELECT 'Sochi', 34, 5 +) +GROUP BY region; + +--Задача 4.4: - Читай их через `avgMerge()` и `uniqMerge()` + +SELECT + region, + avgMerge(avg_age_state), + uniqMerge(active_users_state) +FROM user_metrics +GROUP BY region; + diff --git a/dsolovianov/greenplum/Script-1.sql b/dsolovianov/greenplum/Script-1.sql new file mode 100644 index 0000000..bb78b2a --- /dev/null +++ b/dsolovianov/greenplum/Script-1.sql @@ -0,0 +1,105 @@ +--Витрина dm.lesson_popularity_summary +CREATE MATERIALIZED VIEW dm.lesson_popularity_summary as +select + l.lesson_id, + l.title as lesson_title, + c.course_id, + c.title as course_title, + COUNT(f.user_id) as total_views, + COUNT(DISTINCT f.user_id) as unique_users, + MIN(f.viewed_at) as first_view, + MAX(f.viewed_at) as last_view +FROM core.fact_lesson_views f +JOIN core.dim_lesson l + ON f.lesson_id = l.lesson_id +JOIN core.dim_course c + ON l.course_id = c.course_id +GROUP BY + l.lesson_id, + l.title, + c.course_id, + c.title +order by lesson_id; + +select * from dm.lesson_popularity_summary; + +--Удалил лишний индекс +DROP INDEX core.idx_fact_views_course_id; + +-- Все индексы для CORE-таблиц +SELECT + tablename, + indexname, + indexdef +FROM pg_indexes +WHERE schemaname = 'core' + AND tablename IN ( + 'dim_course', + 'dim_date', + 'dim_lesson', + 'dim_user', + 'enrollments', + 'fact_lesson_views' + ) +ORDER by indexname, tablename; + + +--Витрина dm.inactive_users_summary +CREATE MATERIALIZED VIEW dm.inactive_users_summary as +select + du.user_id, + du.name as user_name, + du.email, + du.age, + COUNT(e.course_id) as enrollments_count, + du.registration_date +from core.dim_user du +left join core.enrollments e + on du.user_id = e.user_id +left join core.fact_lesson_views flv + on du.user_id = flv.user_id +where flv.user_id is NULL +group by + du.user_id, + du.name, + du.email, + du.age, + du.registration_date +order by du.user_id; + +select * from dm.inactive_users_summary; + +--Витрина dm.course_completion_rate +CREATE MATERIALIZED VIEW dm.course_completion_rate as +select + du.user_id, + du.name as user_name, + dc.course_id, + dc.title as course_title, + COUNT(DISTINCT dl.lesson_id) AS lessons_in_course, + COUNT(DISTINCT flv.lesson_id) AS lessons_viewed, + ROUND(COUNT(DISTINCT flv.lesson_id)::numeric / NULLIF(COUNT(DISTINCT dl.lesson_id), 0), 2) AS completion_rate +from core.enrollments e +left join core.dim_user du + on du.user_id = e.user_id +left join core.dim_course dc + on dc.course_id = e.course_id +left join core.dim_lesson dl + on dl.course_id = e.course_id +left join core.fact_lesson_views flv + on flv.user_id = e.user_id + and flv.lesson_id = dl.lesson_id +group by + du.user_id, + du.name, + dc.course_id, + dc.title +order by du.user_id; + +select * from dm.course_completion_rate order by user_id; + +--Этап 5. Проверка +SELECT * FROM dm.lesson_popularity_summary LIMIT 10; +SELECT * FROM dm.inactive_users_summary LIMIT 10; +SELECT * FROM dm.course_completion_rate LIMIT 10; +--Все витрины отображаются корректно. Скрины: "название витрины".png \ No newline at end of file diff --git a/dsolovianov/greenplum/dm.course_completion_rate.png b/dsolovianov/greenplum/dm.course_completion_rate.png new file mode 100644 index 0000000..142dbef Binary files /dev/null and b/dsolovianov/greenplum/dm.course_completion_rate.png differ diff --git a/dsolovianov/greenplum/dm.inactive_users_summary.png b/dsolovianov/greenplum/dm.inactive_users_summary.png new file mode 100644 index 0000000..a0e1aee Binary files /dev/null and b/dsolovianov/greenplum/dm.inactive_users_summary.png differ diff --git a/dsolovianov/greenplum/dm.lesson_popularity_summary.png b/dsolovianov/greenplum/dm.lesson_popularity_summary.png new file mode 100644 index 0000000..f43c677 Binary files /dev/null and b/dsolovianov/greenplum/dm.lesson_popularity_summary.png differ diff --git a/dsolovianov/greenplum/Добавлены индексы.sql b/dsolovianov/greenplum/Добавлены индексы.sql new file mode 100644 index 0000000..7608706 --- /dev/null +++ b/dsolovianov/greenplum/Добавлены индексы.sql @@ -0,0 +1,508 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.4.26 +-- Dumped by pg_dump version 17.5 + +-- Started on 2026-01-17 22:42:00 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET transaction_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- TOC entry 10 (class 2615 OID 25610) +-- Name: core; Type: SCHEMA; Schema: -; Owner: dsolovianov +-- + +CREATE SCHEMA core; + + +ALTER SCHEMA core OWNER TO dsolovianov; + +-- +-- TOC entry 11 (class 2615 OID 25611) +-- Name: dm; Type: SCHEMA; Schema: -; Owner: dsolovianov +-- + +CREATE SCHEMA dm; + + +ALTER SCHEMA dm OWNER TO dsolovianov; + +-- +-- TOC entry 9 (class 2615 OID 25609) +-- Name: raw; Type: SCHEMA; Schema: -; Owner: dsolovianov +-- + +CREATE SCHEMA raw; + + +ALTER SCHEMA raw OWNER TO dsolovianov; + +SET default_tablespace = ''; + +-- +-- TOC entry 273 (class 1259 OID 25635) +-- Name: dim_course; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.dim_course ( + course_id integer NOT NULL, + title text, + category text +); + + +ALTER TABLE core.dim_course OWNER TO dsolovianov; + +-- +-- TOC entry 275 (class 1259 OID 25656) +-- Name: dim_date; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.dim_date ( + date date NOT NULL, + year integer, + month integer, + day integer, + weekday text +); + + +ALTER TABLE core.dim_date OWNER TO dsolovianov; + +-- +-- TOC entry 274 (class 1259 OID 25643) +-- Name: dim_lesson; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.dim_lesson ( + lesson_id integer NOT NULL, + title text, + duration_min integer, + course_id integer +); + + +ALTER TABLE core.dim_lesson OWNER TO dsolovianov; + +-- +-- TOC entry 272 (class 1259 OID 25627) +-- Name: dim_user; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.dim_user ( + user_id integer NOT NULL, + name text, + age integer, + email text, + registration_date date +); + + +ALTER TABLE core.dim_user OWNER TO dsolovianov; + +-- +-- TOC entry 276 (class 1259 OID 25872) +-- Name: enrollments; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.enrollments ( + user_id integer, + course_id integer, + enrolled_at timestamp without time zone +); + + +ALTER TABLE core.enrollments OWNER TO dsolovianov; + +-- +-- TOC entry 277 (class 1259 OID 25885) +-- Name: fact_lesson_views; Type: TABLE; Schema: core; Owner: dsolovianov +-- + +CREATE TABLE core.fact_lesson_views ( + user_id integer, + lesson_id integer, + course_id integer, + viewed_at timestamp without time zone +); + + +ALTER TABLE core.fact_lesson_views OWNER TO dsolovianov; + +-- +-- TOC entry 268 (class 1259 OID 25615) +-- Name: courses; Type: TABLE; Schema: raw; Owner: dsolovianov +-- + +CREATE TABLE raw.courses ( + id integer, + title character varying(50), + category character varying(50), + created_at character varying(50) +); + + +ALTER TABLE raw.courses OWNER TO dsolovianov; + +-- +-- TOC entry 270 (class 1259 OID 25621) +-- Name: enrollments; Type: TABLE; Schema: raw; Owner: dsolovianov +-- + +CREATE TABLE raw.enrollments ( + id integer, + user_id integer, + course_id integer, + enrolled_at character varying(50) +); + + +ALTER TABLE raw.enrollments OWNER TO dsolovianov; + +-- +-- TOC entry 271 (class 1259 OID 25624) +-- Name: lesson_views; Type: TABLE; Schema: raw; Owner: dsolovianov +-- + +CREATE TABLE raw.lesson_views ( + id integer, + user_id integer, + lesson_id integer, + viewed_at character varying(50) +); + + +ALTER TABLE raw.lesson_views OWNER TO dsolovianov; + +-- +-- TOC entry 269 (class 1259 OID 25618) +-- Name: lessons; Type: TABLE; Schema: raw; Owner: dsolovianov +-- + +CREATE TABLE raw.lessons ( + id integer, + course_id integer, + title character varying(50), + duration_min integer +); + + +ALTER TABLE raw.lessons OWNER TO dsolovianov; + +-- +-- TOC entry 267 (class 1259 OID 25612) +-- Name: users; Type: TABLE; Schema: raw; Owner: dsolovianov +-- + +CREATE TABLE raw.users ( + id integer, + name character varying(50), + age integer, + email character varying(50), + registration_date character varying(50) +); + + +ALTER TABLE raw.users OWNER TO dsolovianov; + +-- +-- TOC entry 2506 (class 0 OID 25635) +-- Dependencies: 273 +-- Data for Name: dim_course; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_course (course_id, title, category) FROM stdin; +2 Python для анализа данных programming +1 SQL для начинающих data +3 BI с нуля business +\. + + +-- +-- TOC entry 2508 (class 0 OID 25656) +-- Dependencies: 275 +-- Data for Name: dim_date; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_date (date, year, month, day, weekday) FROM stdin; +2023-01-15 2023 1 15 Sunday +2023-01-16 2023 1 16 Monday +2023-01-21 2023 1 21 Saturday +2023-01-20 2023 1 20 Friday +2023-03-05 2023 3 5 Sunday +2023-02-01 2023 2 1 Wednesday +2023-04-02 2023 4 2 Sunday +2023-03-06 2023 3 6 Monday +2023-04-01 2023 4 1 Saturday +2023-04-03 2023 4 3 Monday +\. + + +-- +-- TOC entry 2507 (class 0 OID 25643) +-- Dependencies: 274 +-- Data for Name: dim_lesson; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_lesson (lesson_id, title, duration_min, course_id) FROM stdin; +4 Основы BI 12 3 +5 Метрики и дашборды 18 3 +2 JOIN 15 1 +1 SELECT и FROM 10 1 +3 Pandas 20 2 +\. + + +-- +-- TOC entry 2505 (class 0 OID 25627) +-- Dependencies: 272 +-- Data for Name: dim_user; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_user (user_id, name, age, email, registration_date) FROM stdin; +3 Charlie 22 charlie@mail.com 2023-02-20 +1 Alice 25 alice@mail.com 2023-01-10 +2 Bob 30 bob@gmail.com 2023-02-05 +5 Ethan 35 ethan@gmail.com 2023-03-10 +4 Diana 28 diana@mail.com 2023-03-01 +\. + + +-- +-- TOC entry 2509 (class 0 OID 25872) +-- Dependencies: 276 +-- Data for Name: enrollments; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.enrollments (user_id, course_id, enrolled_at) FROM stdin; +4 3 2023-04-01 00:00:00 +1 2 2023-02-01 00:00:00 +2 1 2023-01-20 00:00:00 +1 1 2023-01-15 00:00:00 +3 2 2023-03-05 00:00:00 +\. + + +-- +-- TOC entry 2510 (class 0 OID 25885) +-- Dependencies: 277 +-- Data for Name: fact_lesson_views; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.fact_lesson_views (user_id, lesson_id, course_id, viewed_at) FROM stdin; +2 1 1 2023-01-21 09:00:00 +1 2 1 2023-01-16 10:15:00 +3 3 2 2023-03-06 12:00:00 +1 1 1 2023-01-16 10:00:00 +4 4 3 2023-04-02 10:00:00 +4 5 3 2023-04-03 10:00:00 +\. + + +-- +-- TOC entry 2501 (class 0 OID 25615) +-- Dependencies: 268 +-- Data for Name: courses; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.courses (id, title, category, created_at) FROM stdin; +3 BI с нуля business 2023-03-01 +1 SQL для начинающих data 2023-01-01 +2 Python для анализа данных programming 2023-01-15 +\. + + +-- +-- TOC entry 2503 (class 0 OID 25621) +-- Dependencies: 270 +-- Data for Name: enrollments; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.enrollments (id, user_id, course_id, enrolled_at) FROM stdin; +1 1 1 2023-01-15 +2 1 2 2023-02-01 +3 2 1 2023-01-20 +4 3 2 2023-03-05 +5 4 3 2023-04-01 +\. + + +-- +-- TOC entry 2504 (class 0 OID 25624) +-- Dependencies: 271 +-- Data for Name: lesson_views; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.lesson_views (id, user_id, lesson_id, viewed_at) FROM stdin; +2 1 2 2023-01-16 10:15:00.000 +1 1 1 2023-01-16 10:00:00.000 +3 2 1 2023-01-21 09:00:00.000 +5 4 4 2023-04-02 10:00:00.000 +4 3 3 2023-03-06 12:00:00.000 +6 4 5 2023-04-03 10:00:00.000 +\. + + +-- +-- TOC entry 2502 (class 0 OID 25618) +-- Dependencies: 269 +-- Data for Name: lessons; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.lessons (id, course_id, title, duration_min) FROM stdin; +1 1 SELECT и FROM 10 +2 1 JOIN 15 +3 2 Pandas 20 +4 3 Основы BI 12 +5 3 Метрики и дашборды 18 +\. + + +-- +-- TOC entry 2500 (class 0 OID 25612) +-- Dependencies: 267 +-- Data for Name: users; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.users (id, name, age, email, registration_date) FROM stdin; +1 Alice 25 alice@mail.com 2023-01-10 +2 Bob 30 bob@gmail.com 2023-02-05 +3 Charlie 22 charlie@mail.com 2023-02-20 +5 Ethan 35 ethan@gmail.com 2023-03-10 +4 Diana 28 diana@mail.com 2023-03-01 +\. + + +-- +-- TOC entry 2314 (class 2606 OID 25642) +-- Name: dim_course dim_course_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_course + ADD CONSTRAINT dim_course_pkey PRIMARY KEY (course_id); + + +-- +-- TOC entry 2319 (class 2606 OID 25663) +-- Name: dim_date dim_date_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_date + ADD CONSTRAINT dim_date_pkey PRIMARY KEY (date); + + +-- +-- TOC entry 2316 (class 2606 OID 25650) +-- Name: dim_lesson dim_lesson_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_lesson + ADD CONSTRAINT dim_lesson_pkey PRIMARY KEY (lesson_id); + + +-- +-- TOC entry 2312 (class 2606 OID 25634) +-- Name: dim_user dim_user_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_user + ADD CONSTRAINT dim_user_pkey PRIMARY KEY (user_id); + + +-- +-- TOC entry 2317 (class 1259 OID 25906) +-- Name: idx_dim_lesson_course_id; Type: INDEX; Schema: core; Owner: dsolovianov +-- +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + + +/* +1) Создание INDEX на таблицы в CORE-слое +*/ + +CREATE INDEX idx_dim_lesson_course_id ON core.dim_lesson USING btree (course_id); + +CREATE INDEX idx_enrollments_course_id ON core.enrollments USING btree (course_id); + +CREATE INDEX idx_fact_views_course_id ON core.fact_lesson_views USING btree (course_id); + +CREATE INDEX idx_fact_views_course_viewed_at ON core.fact_lesson_views USING btree (course_id, viewed_at); + +CREATE INDEX idx_fact_views_lesson_id ON core.fact_lesson_views USING btree (lesson_id); + +CREATE INDEX idx_fact_views_user_id ON core.fact_lesson_views USING btree (user_id); + +CREATE INDEX idx_fact_views_user_viewed_at ON core.fact_lesson_views USING btree (user_id, viewed_at); +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + + + +ALTER TABLE ONLY core.dim_lesson + ADD CONSTRAINT dim_lesson_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2327 (class 2606 OID 25880) +-- Name: enrollments enrollments_course_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.enrollments + ADD CONSTRAINT enrollments_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2328 (class 2606 OID 25875) +-- Name: enrollments enrollments_user_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.enrollments + ADD CONSTRAINT enrollments_user_id_fkey FOREIGN KEY (user_id) REFERENCES core.dim_user(user_id); + + +-- +-- TOC entry 2329 (class 2606 OID 25898) +-- Name: fact_lesson_views fact_lesson_views_course_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2330 (class 2606 OID 25893) +-- Name: fact_lesson_views fact_lesson_views_lesson_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_lesson_id_fkey FOREIGN KEY (lesson_id) REFERENCES core.dim_lesson(lesson_id); + + +-- +-- TOC entry 2331 (class 2606 OID 25888) +-- Name: fact_lesson_views fact_lesson_views_user_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_user_id_fkey FOREIGN KEY (user_id) REFERENCES core.dim_user(user_id); + + +-- Completed on 2026-01-17 22:42:02 + +-- +-- PostgreSQL database dump complete +-- + diff --git a/dsolovianov/greenplum/Этапы 1-3.sql b/dsolovianov/greenplum/Этапы 1-3.sql new file mode 100644 index 0000000..045de55 --- /dev/null +++ b/dsolovianov/greenplum/Этапы 1-3.sql @@ -0,0 +1,417 @@ +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET transaction_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +-- ЭТАП 1 +-- 1.1 - СОЗДАНИЕ СХЕМ + +CREATE SCHEMA core; + + +ALTER SCHEMA core OWNER TO dsolovianov; + + +CREATE SCHEMA dm; + + +ALTER SCHEMA dm OWNER TO dsolovianov; + + +CREATE SCHEMA raw; + + +ALTER SCHEMA raw OWNER TO dsolovianov; + +SET default_tablespace = ''; + + + +-- 1.2 - Создание raw-таблиц + +CREATE TABLE raw.courses ( + id integer, + title character varying(50), + category character varying(50), + created_at character varying(50) +); + + +ALTER TABLE raw.courses OWNER TO dsolovianov; + + +CREATE TABLE raw.enrollments ( + id integer, + user_id integer, + course_id integer, + enrolled_at character varying(50) +); + + +ALTER TABLE raw.enrollments OWNER TO dsolovianov; + + +CREATE TABLE raw.lesson_views ( + id integer, + user_id integer, + lesson_id integer, + viewed_at character varying(50) +); + + +ALTER TABLE raw.lesson_views OWNER TO dsolovianov; + + +CREATE TABLE raw.lessons ( + id integer, + course_id integer, + title character varying(50), + duration_min integer +); + + +ALTER TABLE raw.lessons OWNER TO dsolovianov; + + +CREATE TABLE raw.users ( + id integer, + name character varying(50), + age integer, + email character varying(50), + registration_date character varying(50) +); + + +ALTER TABLE raw.users OWNER TO dsolovianov; + + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Этап 3. Слой Core + +CREATE TABLE core.dim_course ( + course_id integer NOT NULL, + title text, + category text +); + + +ALTER TABLE core.dim_course OWNER TO dsolovianov; + + +CREATE TABLE core.dim_date ( + date date NOT NULL, + year integer, + month integer, + day integer, + weekday text +); + + +ALTER TABLE core.dim_date OWNER TO dsolovianov; + + +CREATE TABLE core.dim_lesson ( + lesson_id integer NOT NULL, + title text, + duration_min integer, + course_id integer +); + + +ALTER TABLE core.dim_lesson OWNER TO dsolovianov; + + +CREATE TABLE core.dim_user ( + user_id integer NOT NULL, + name text, + age integer, + email text, + registration_date date +); + + +ALTER TABLE core.dim_user OWNER TO dsolovianov; + + +CREATE TABLE core.enrollments ( + user_id integer, + course_id integer, + enrolled_at timestamp without time zone +); + + +ALTER TABLE core.enrollments OWNER TO dsolovianov; + + +CREATE TABLE core.fact_lesson_views ( + user_id integer, + lesson_id integer, + course_id integer, + viewed_at timestamp without time zone +); + + +ALTER TABLE core.fact_lesson_views OWNER TO dsolovianov; + +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +COPY core.dim_course (course_id, title, category) FROM stdin; +2 Python для анализа данных programming +1 SQL для начинающих data +3 BI с нуля business +\. + + +COPY core.dim_date (date, year, month, day, weekday) FROM stdin; +2023-01-15 2023 1 15 Sunday +2023-01-16 2023 1 16 Monday +2023-01-21 2023 1 21 Saturday +2023-01-20 2023 1 20 Friday +2023-03-05 2023 3 5 Sunday +2023-02-01 2023 2 1 Wednesday +2023-04-02 2023 4 2 Sunday +2023-03-06 2023 3 6 Monday +2023-04-01 2023 4 1 Saturday +2023-04-03 2023 4 3 Monday +\. + + +-- +-- TOC entry 2500 (class 0 OID 25643) +-- Dependencies: 274 +-- Data for Name: dim_lesson; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_lesson (lesson_id, title, duration_min, course_id) FROM stdin; +4 Основы BI 12 3 +5 Метрики и дашборды 18 3 +2 JOIN 15 1 +1 SELECT и FROM 10 1 +3 Pandas 20 2 +\. + + +-- +-- TOC entry 2498 (class 0 OID 25627) +-- Dependencies: 272 +-- Data for Name: dim_user; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.dim_user (user_id, name, age, email, registration_date) FROM stdin; +3 Charlie 22 charlie@mail.com 2023-02-20 +1 Alice 25 alice@mail.com 2023-01-10 +2 Bob 30 bob@gmail.com 2023-02-05 +5 Ethan 35 ethan@gmail.com 2023-03-10 +4 Diana 28 diana@mail.com 2023-03-01 +\. + + +-- +-- TOC entry 2502 (class 0 OID 25872) +-- Dependencies: 276 +-- Data for Name: enrollments; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.enrollments (user_id, course_id, enrolled_at) FROM stdin; +4 3 2023-04-01 00:00:00 +1 2 2023-02-01 00:00:00 +2 1 2023-01-20 00:00:00 +1 1 2023-01-15 00:00:00 +3 2 2023-03-05 00:00:00 +\. + + +-- +-- TOC entry 2503 (class 0 OID 25885) +-- Dependencies: 277 +-- Data for Name: fact_lesson_views; Type: TABLE DATA; Schema: core; Owner: dsolovianov +-- + +COPY core.fact_lesson_views (user_id, lesson_id, course_id, viewed_at) FROM stdin; +2 1 1 2023-01-21 09:00:00 +1 2 1 2023-01-16 10:15:00 +3 3 2 2023-03-06 12:00:00 +1 1 1 2023-01-16 10:00:00 +4 4 3 2023-04-02 10:00:00 +4 5 3 2023-04-03 10:00:00 +\. + + +-- +-- TOC entry 2494 (class 0 OID 25615) +-- Dependencies: 268 +-- Data for Name: courses; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.courses (id, title, category, created_at) FROM stdin; +3 BI с нуля business 2023-03-01 +1 SQL для начинающих data 2023-01-01 +2 Python для анализа данных programming 2023-01-15 +\. + + +-- +-- TOC entry 2496 (class 0 OID 25621) +-- Dependencies: 270 +-- Data for Name: enrollments; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.enrollments (id, user_id, course_id, enrolled_at) FROM stdin; +1 1 1 2023-01-15 +2 1 2 2023-02-01 +3 2 1 2023-01-20 +4 3 2 2023-03-05 +5 4 3 2023-04-01 +\. + + +-- +-- TOC entry 2497 (class 0 OID 25624) +-- Dependencies: 271 +-- Data for Name: lesson_views; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.lesson_views (id, user_id, lesson_id, viewed_at) FROM stdin; +2 1 2 2023-01-16 10:15:00.000 +1 1 1 2023-01-16 10:00:00.000 +3 2 1 2023-01-21 09:00:00.000 +5 4 4 2023-04-02 10:00:00.000 +4 3 3 2023-03-06 12:00:00.000 +6 4 5 2023-04-03 10:00:00.000 +\. + + +-- +-- TOC entry 2495 (class 0 OID 25618) +-- Dependencies: 269 +-- Data for Name: lessons; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.lessons (id, course_id, title, duration_min) FROM stdin; +1 1 SELECT и FROM 10 +2 1 JOIN 15 +3 2 Pandas 20 +4 3 Основы BI 12 +5 3 Метрики и дашборды 18 +\. + + +-- +-- TOC entry 2493 (class 0 OID 25612) +-- Dependencies: 267 +-- Data for Name: users; Type: TABLE DATA; Schema: raw; Owner: dsolovianov +-- + +COPY raw.users (id, name, age, email, registration_date) FROM stdin; +1 Alice 25 alice@mail.com 2023-01-10 +2 Bob 30 bob@gmail.com 2023-02-05 +3 Charlie 22 charlie@mail.com 2023-02-20 +5 Ethan 35 ethan@gmail.com 2023-03-10 +4 Diana 28 diana@mail.com 2023-03-01 +\. + + +-- +-- TOC entry 2314 (class 2606 OID 25642) +-- Name: dim_course dim_course_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_course + ADD CONSTRAINT dim_course_pkey PRIMARY KEY (course_id); + + +-- +-- TOC entry 2318 (class 2606 OID 25663) +-- Name: dim_date dim_date_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_date + ADD CONSTRAINT dim_date_pkey PRIMARY KEY (date); + + +-- +-- TOC entry 2316 (class 2606 OID 25650) +-- Name: dim_lesson dim_lesson_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_lesson + ADD CONSTRAINT dim_lesson_pkey PRIMARY KEY (lesson_id); + + +-- +-- TOC entry 2312 (class 2606 OID 25634) +-- Name: dim_user dim_user_pkey; Type: CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_user + ADD CONSTRAINT dim_user_pkey PRIMARY KEY (user_id); + + +-- +-- TOC entry 2319 (class 2606 OID 25651) +-- Name: dim_lesson dim_lesson_course_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.dim_lesson + ADD CONSTRAINT dim_lesson_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2320 (class 2606 OID 25880) +-- Name: enrollments enrollments_course_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.enrollments + ADD CONSTRAINT enrollments_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2321 (class 2606 OID 25875) +-- Name: enrollments enrollments_user_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.enrollments + ADD CONSTRAINT enrollments_user_id_fkey FOREIGN KEY (user_id) REFERENCES core.dim_user(user_id); + + +-- +-- TOC entry 2322 (class 2606 OID 25898) +-- Name: fact_lesson_views fact_lesson_views_course_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_course_id_fkey FOREIGN KEY (course_id) REFERENCES core.dim_course(course_id); + + +-- +-- TOC entry 2323 (class 2606 OID 25893) +-- Name: fact_lesson_views fact_lesson_views_lesson_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_lesson_id_fkey FOREIGN KEY (lesson_id) REFERENCES core.dim_lesson(lesson_id); + + +-- +-- TOC entry 2324 (class 2606 OID 25888) +-- Name: fact_lesson_views fact_lesson_views_user_id_fkey; Type: FK CONSTRAINT; Schema: core; Owner: dsolovianov +-- + +ALTER TABLE ONLY core.fact_lesson_views + ADD CONSTRAINT fact_lesson_views_user_id_fkey FOREIGN KEY (user_id) REFERENCES core.dim_user(user_id); + + +-- Completed on 2026-01-14 21:29:24 + +-- +-- PostgreSQL database dump complete +-- + diff --git a/dsolovianov/postgresql/courses_202601031845.csv b/dsolovianov/postgresql/courses_202601031845.csv new file mode 100644 index 0000000..f604a2e --- /dev/null +++ b/dsolovianov/postgresql/courses_202601031845.csv @@ -0,0 +1,4 @@ +"id","title","category","created_at" +1,SQL для начинающих,data,2023-01-01 +2,Python для анализа данных,programming,2023-01-15 +3,BI с нуля,business,2023-03-01 diff --git a/dsolovianov/postgresql/enrollments_202601031845.csv b/dsolovianov/postgresql/enrollments_202601031845.csv new file mode 100644 index 0000000..7b27fa5 --- /dev/null +++ b/dsolovianov/postgresql/enrollments_202601031845.csv @@ -0,0 +1,6 @@ +"id","user_id","course_id","enrolled_at" +1,1,1,2023-01-15 +2,1,2,2023-02-01 +3,2,1,2023-01-20 +4,3,2,2023-03-05 +5,4,3,2023-04-01 diff --git a/dsolovianov/postgresql/lesson_views_202601031846.csv b/dsolovianov/postgresql/lesson_views_202601031846.csv new file mode 100644 index 0000000..23e3561 --- /dev/null +++ b/dsolovianov/postgresql/lesson_views_202601031846.csv @@ -0,0 +1,7 @@ +"id","user_id","lesson_id","viewed_at" +1,1,1,2023-01-16 10:00:00.000 +2,1,2,2023-01-16 10:15:00.000 +3,2,1,2023-01-21 09:00:00.000 +4,3,3,2023-03-06 12:00:00.000 +5,4,4,2023-04-02 10:00:00.000 +6,4,5,2023-04-03 10:00:00.000 diff --git a/dsolovianov/postgresql/lessons_202601031846.csv b/dsolovianov/postgresql/lessons_202601031846.csv new file mode 100644 index 0000000..24505cf --- /dev/null +++ b/dsolovianov/postgresql/lessons_202601031846.csv @@ -0,0 +1,6 @@ +"id","course_id","title","duration_min" +1,1,SELECT и FROM,10 +2,1,JOIN,15 +3,2,Pandas,20 +4,3,Основы BI,12 +5,3,Метрики и дашборды,18 diff --git a/dsolovianov/postgresql/users_202601031846.csv b/dsolovianov/postgresql/users_202601031846.csv new file mode 100644 index 0000000..54c69df --- /dev/null +++ b/dsolovianov/postgresql/users_202601031846.csv @@ -0,0 +1,6 @@ +"id","name","age","email","registration_date" +1,Alice,25,alice@mail.com,2023-01-10 +2,Bob,30,bob@gmail.com,2023-02-05 +3,Charlie,22,charlie@mail.com,2023-02-20 +4,Diana,28,diana@mail.com,2023-03-01 +5,Ethan,35,ethan@gmail.com,2023-03-10