Этап 3. Слой Core — обогащённые данные. Пет проект: DWH. РАБОТА НАД ОШИБКАМИ - добавил NULL в измерения и факты.
This commit is contained in:
@@ -5,23 +5,23 @@ CREATE TABLE core.dim_user (
|
|||||||
user_id int PRIMARY KEY,
|
user_id int PRIMARY KEY,
|
||||||
name text,
|
name text,
|
||||||
age int,
|
age int,
|
||||||
email text,
|
email text NOT NULL,
|
||||||
registration_date date
|
registration_date date NOT NULL
|
||||||
) DISTRIBUTED BY (user_id);
|
) DISTRIBUTED BY (user_id);
|
||||||
|
|
||||||
--DROP TABLE IF EXISTS core.dim_course;
|
--DROP TABLE IF EXISTS core.dim_course;
|
||||||
CREATE TABLE core.dim_course (
|
CREATE TABLE core.dim_course (
|
||||||
course_id int PRIMARY KEY,
|
course_id int PRIMARY KEY,
|
||||||
title text,
|
title text NOT NULL,
|
||||||
category text
|
category text
|
||||||
) DISTRIBUTED BY (course_id);
|
) DISTRIBUTED BY (course_id);
|
||||||
|
|
||||||
--DROP TABLE IF EXISTS core.dim_lesson;
|
--DROP TABLE IF EXISTS core.dim_lesson;
|
||||||
CREATE TABLE core.dim_lesson (
|
CREATE TABLE core.dim_lesson (
|
||||||
lesson_id int PRIMARY KEY,
|
lesson_id int PRIMARY KEY,
|
||||||
title text,
|
title text NOT NULL,
|
||||||
duration_min int,
|
duration_min int,
|
||||||
course_id int REFERENCES core.dim_course(course_id)
|
course_id int NOT NULL REFERENCES core.dim_course(course_id)
|
||||||
) DISTRIBUTED BY (lesson_id);
|
) DISTRIBUTED BY (lesson_id);
|
||||||
|
|
||||||
--DROP TABLE IF EXISTS core.dim_date;
|
--DROP TABLE IF EXISTS core.dim_date;
|
||||||
@@ -37,17 +37,17 @@ CREATE TABLE core.dim_date (
|
|||||||
-- 5
|
-- 5
|
||||||
--DROP TABLE IF EXISTS core.fact_lesson_views;
|
--DROP TABLE IF EXISTS core.fact_lesson_views;
|
||||||
CREATE TABLE core.fact_lesson_views (
|
CREATE TABLE core.fact_lesson_views (
|
||||||
user_id int REFERENCES core.dim_user(user_id),
|
user_id int NOT NULL REFERENCES core.dim_user(user_id),
|
||||||
lesson_id int REFERENCES core.dim_lesson(lesson_id),
|
lesson_id int NOT NULL REFERENCES core.dim_lesson(lesson_id),
|
||||||
course_id int REFERENCES core.dim_course(course_id),
|
course_id int NOT NULL REFERENCES core.dim_course(course_id),
|
||||||
viewed_at timestamp
|
viewed_at timestamp NOT NULL
|
||||||
) DISTRIBUTED BY (user_id);
|
) DISTRIBUTED BY (user_id);
|
||||||
|
|
||||||
--DROP TABLE IF EXISTS core.enrollments;
|
--DROP TABLE IF EXISTS core.enrollments;
|
||||||
CREATE TABLE core.enrollments (
|
CREATE TABLE core.enrollments (
|
||||||
user_id int REFERENCES core.dim_user(user_id),
|
user_id int NOT NULL REFERENCES core.dim_user(user_id),
|
||||||
course_id int REFERENCES core.dim_course(course_id),
|
course_id int NOT NULL REFERENCES core.dim_course(course_id),
|
||||||
enrolled_at timestamp
|
enrolled_at timestamp NOT NULL
|
||||||
) DISTRIBUTED BY (user_id);
|
) DISTRIBUTED BY (user_id);
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
raw.lesson_views lv
|
raw.lesson_views lv
|
||||||
JOIN
|
JOIN
|
||||||
raw.lessons l ON lv.lesson_id = l.id
|
raw.lessons l ON lv.lesson_id = l.id;
|
||||||
|
|
||||||
INSERT INTO core.enrollments (user_id, course_id, enrolled_at)
|
INSERT INTO core.enrollments (user_id, course_id, enrolled_at)
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
Reference in New Issue
Block a user