{"id":2065,"date":"2024-01-30T11:17:08","date_gmt":"2024-01-30T02:17:08","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=2065"},"modified":"2024-01-30T11:17:14","modified_gmt":"2024-01-30T02:17:14","slug":"dimensional-modeling-on-postgres-dvdrental","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2024\/01\/30\/dimensional-modeling-on-postgres-dvdrental\/","title":{"rendered":"PostgreSQL: dvdrental \u3092 Dimensional Model \u306b\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\nDimensional Model \u306e\u30c7\u30e2\u74b0\u5883\u304c\u6b32\u3057\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n<p>\u3053\u306a\u3044\u3060\u7acb\u3066\u305f PostgreSQL \u306e\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u30b9\u30bf\u30fc\u30b9\u30ad\u30fc\u30de\u306b\u3059\u308b\u3002<br \/>\n\u3060\u3044\u3076\u524d\u306b Ralph Kimball \u306e\u672c\u3092\u8aad\u3093\u3060\u306e\u3067\u305d\u308c\u3063\u307d\u304f\u9069\u5f53\u306b\u4f5c\u308b\u3002<\/p>\n<p>\u904e\u53bb\u306e\u6295\u7a3f\u306f\u3053\u3061\u3089<br \/>\n\u2192 <a href=\"https:\/\/www.kwonline.org\/memo2\/2023\/11\/28\/load-postgresql-sample-db-dvdrental\/\" rel=\"noopener\" target=\"_blank\">PostgreSQL \u306e\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u7acb\u3066\u308b<\/a><br \/>\n\u2192 <a href=\"https:\/\/www.kwonline.org\/memo2\/2021\/05\/25\/the-data-warehouse-toolkit-4step-dimenstional-design\/\" rel=\"noopener\" target=\"_blank\">The Data Warehouse Toolkit \u3092\u8aad\u3080 #1: \u57fa\u672c\u306e4\u30b9\u30c6\u30c3\u30d7<\/a><\/p>\n<h2>Git Repository<\/h2>\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f Github \u306b\u8f09\u305b\u3066\u304a\u3044\u305f\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/youngdongk\/dvdrental-dimensional\" rel=\"noopener\" target=\"_blank\">youngdongk\/dvdrental-dimensional &#8211; GitHub<\/a><\/p>\n<h2>ER \u56f3<\/h2>\n<p>\u3053\u3046\u3044\u3046\u30b9\u30ad\u30fc\u30de\u306b\u3057\u305f\u3002<\/p>\n<div id=\"attachment_2067\" style=\"width: 635px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2067\" src=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-1024x558.png\" alt=\"Dimentional Model - dvdrental\" width=\"625\" height=\"341\" class=\"size-large wp-image-2067\" srcset=\"https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-1024x558.png 1024w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-300x163.png 300w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-768x418.png 768w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-1536x837.png 1536w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd-624x340.png 624w, https:\/\/www.kwonline.org\/memo2\/wp-content\/uploads\/2024\/01\/dvdrental_dimensional_erd.png 1542w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><p id=\"caption-attachment-2067\" class=\"wp-caption-text\">Dimentional Model &#8211; dvdrental<\/p><\/div>\n<p>Git \u30ec\u30dd\u30b8\u30c8\u30ea\u306b\u3042\u308b dvdrental_sales_dw.vuerd.json \u3092 VSCode \u306e ERD Editor \u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3\u3067\u958b\u3051\u308b\u3002<\/p>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=dineug.vuerd-vscode\" rel=\"noopener\" target=\"_blank\">ERD Editor &#8211; Visual Studio Marketplace<\/a><\/p>\n<h2>\u5927\u798f\u5e33\u30af\u30a8\u30ea<\/h2>\n<p>\u3067\u3001\u7d50\u5c40\u6700\u7d42\u7684\u306b\u5168\u90e8\u7e4b\u3052\u305f\u300c\u5927\u798f\u5e33\u300d\u7684\u306a\u30ef\u30a4\u30c9\u30c6\u30fc\u30d6\u30eb\u306a\u30c7\u30fc\u30bf\u30de\u30fc\u30c8\u304c\u6b32\u3057\u3044\u3001\u3063\u3066\u306a\u308b\u306e\u3067 SQL \u3067\u7d50\u5408\u3059\u308b\u3002<br \/>\n\u3053\u3053\u306b\u304a\u3044\u3066\u3042\u308b\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/youngdongk\/dvdrental-dimensional\/blob\/main\/sql\/mart_rental.sql\" rel=\"noopener\" target=\"_blank\">dvdrental-dimensional\/sql\/mart_rental.sql at main \u00b7 youngdongk\/dvdrental-dimensional<\/a><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT\r\n    r.rental_id,\r\n    s.store_id,\r\n    sc.city_id as store_city_id,\r\n    sc.city as store_city,\r\n    sc.country as store_country,\r\n    f.film_id,\r\n    f.title,\r\n    f.category,\r\n    f.release_year,\r\n    f.rating,\r\n    f.length,\r\n    f.length_label,\r\n    c.customer_id,\r\n    c.full_name,\r\n    c.email,\r\n    cc.city_id as customer_city_id,\r\n    cc.city as customer_city,\r\n    cc.country as customer_counrry,\r\n    r.rental_date,\r\n    r.payment_date,\r\n    r.return_date,\r\n    r.amount,\r\n    r.rental_duration\r\nFROM\r\n    public.fact_rental as r\r\n    inner join public.dim_customer as c on r.customer_key = c.customer_key \r\n        and r.rental_date between c.create_date and c.expire_date\r\n    inner join public.dim_store as s on r.store_key = s.store_key\r\n        and r.rental_date between s.create_date and s.expire_date\r\n    inner join public.dim_city as sc on r.store_city_key = sc.city_key\r\n        and r.rental_date between sc.create_date and sc.expire_date\r\n    inner join public.dim_film as f on r.film_key = f.film_key\r\n        and r.rental_date between f.create_date and f.expire_date\r\n    inner join public.dim_city as cc on r.customer_city_key = cc.city_key\r\n        and r.rental_date between cc.create_date and cc.expire_date\r\n;\r\n<\/pre>\n<p>Dimension \u30c6\u30fc\u30d6\u30eb\u306f SCD type2 \u3092\u5b9f\u88c5\u3057\u3066\u308b\u306e\u3067\u3001 JOIN \u306e\u969b\u306b\u306f key \u306e\u4ed6\u306b create_date \u3068 expire_date \u3082\u6761\u4ef6\u306b\u8ffd\u52a0\u3057\u3066\u3042\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Dimensional Model \u306e\u30c7\u30e2\u74b0\u5883\u304c\u6b32\u3057\u304b\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002 \u3053\u306a\u3044\u3060\u7acb\u3066\u305f PostgreSQL \u306e\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u30b9\u30bf\u30fc\u30b9\u30ad\u30fc\u30de\u306b\u3059\u308b\u3002 \u3060\u3044\u3076\u524d\u306b Ralph Kimba [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,8,26,20],"tags":[],"class_list":["post-2065","post","type-post","status-publish","format-standard","hentry","category-data-engineering","category-linux","category-postgresql","category-sql"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=2065"}],"version-history":[{"count":7,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2065\/revisions"}],"predecessor-version":[{"id":2073,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2065\/revisions\/2073"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=2065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=2065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=2065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}