Advertisement
Mad_Axell

Untitled

Feb 12th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2. DROP TABLE IF EXISTS MADAXELLYANDEXRU__STAGING.groups;
  3. DROP TABLE IF EXISTS MADAXELLYANDEXRU__STAGING.dialogs;
  4. DROP TABLE IF EXISTS MADAXELLYANDEXRU__STAGING.users;
  5.  
  6.  
  7. CREATE TABLE IF NOT EXISTS MADAXELLYANDEXRU__STAGING.users
  8. (
  9. id int NOT NULL PRIMARY KEY,
  10. chat_name varchar(200) NOT NULL,
  11. registration_dt timestamp NOT NULL,
  12. country varchar(200) NOT NULL,
  13. age int NOT NULL
  14. )
  15. order by id
  16. SEGMENTED BY hash(id) all nodes
  17. ;
  18.  
  19. CREATE TABLE IF NOT EXISTS MADAXELLYANDEXRU__STAGING.groups
  20. (
  21. id int NOT NULL PRIMARY KEY,
  22. admin_id int REFERENCES users(id) NOT NULL,
  23. group_name varchar(100) NOT NULL,
  24. registration_dt timestamp NOT NULL,
  25. is_private BOOLEAN NOT NULL
  26. )
  27. order by id, admin_id
  28. PARTITION BY registration_dt::date
  29. GROUP BY calendar_hierarchy_day(registration_dt::date, 3, 2)
  30. /*SEGMENTED BY hash(id) all nodes*/
  31. ;
  32.  
  33. CREATE TABLE IF NOT EXISTS MADAXELLYANDEXRU__STAGING.dialogs
  34. (
  35. message_id int NOT NULL PRIMARY KEY,
  36. message_ts timestamp NOT NULL,
  37. message_from int REFERENCES users(id) NOT NULL,
  38. message_to int REFERENCES users(id) NOT NULL,
  39. message varchar(1000) NOT NULL,
  40. message_group int
  41. -- message_type varchar(100)
  42. )
  43. order by message_id/*, message_from, message_ts*/
  44. /*SEGMENTED BY hash(message_id) all nodes*/
  45. PARTITION BY message_ts::DATE
  46. GROUP BY calendar_hierarchy_day(message_ts::DATE, 3, 2)
  47. ;
  48.  
  49. COPY MADAXELLYANDEXRU__STAGING.users
  50. FROM LOCAL 'D:\YandexDisk\Education\Yandex Практикум\DataEngineer\Sprint 6\s6-lessons-main\s6-lessons-main\data\users.csv'
  51. DELIMITER ','
  52. REJECTED DATA AS TABLE MADAXELLYANDEXRU__STAGING.users_rej;
  53.  
  54. COPY MADAXELLYANDEXRU__STAGING.groups
  55. FROM LOCAL 'D:\YandexDisk\Education\Yandex Практикум\DataEngineer\Sprint 6\s6-lessons-main\s6-lessons-main\data\groups.csv'
  56. DELIMITER ','
  57. REJECTED DATA AS TABLE MADAXELLYANDEXRU__STAGING.groups_rej;
  58.  
  59. COPY MADAXELLYANDEXRU__STAGING.dialogs
  60. FROM LOCAL 'D:\YandexDisk\Education\Yandex Практикум\DataEngineer\Sprint 6\s6-lessons-main\s6-lessons-main\data\dialogs.csv'
  61. DELIMITER ','
  62. REJECTED DATA AS TABLE MADAXELLYANDEXRU__STAGING.dialogs_rej;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement