Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild entire (small) DWH in one go
- Loading branch information
Showing
23 changed files
with
106 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
-- Start by creating a new dimension table, which we use to copy over the production one. | ||
-- Regenerate entire dimension from scratch. | ||
|
||
DROP TABLE IF EXISTS dim_customer_new; | ||
FROM (SELECT | ||
row_number() OVER () AS dim_customer_key | ||
, customer_id | ||
, LEAD(customer_id) OVER (PARTITION BY customer_id ORDER BY change_date) as id_lead | ||
, LAST_VALUE(cust_name) OVER (PARTITION BY customer_id ORDER BY change_date RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as cust_name | ||
, row_number() OVER (PARTITION BY customer_id ORDER BY change_date) AS scd_version | ||
, street | ||
, city | ||
, change_date | ||
, LEAD(change_date) OVER (PARTITION BY customer_id ORDER BY change_date) as end_date | ||
FROM | ||
customer_staging) a | ||
INSERT OVERWRITE TABLE dim_customer PARTITION(scd_active='T') | ||
SELECT a.dim_customer_key, a.customer_id, a.cust_name, a.street, a.city, scd_version, TO_DATE(a.change_date) as scd_start_date, TO_DATE('9999-12-31') as scd_end_date | ||
WHERE a.id_lead IS NULL | ||
|
||
CREATE TABLE dim_customer_new | ||
LIKE dim_customer | ||
STORED AS ORC; | ||
INSERT OVERWRITE TABLE dim_customer PARTITION(scd_active='F') | ||
SELECT a.dim_customer_key, a.customer_id, a.cust_name, a.street, a.city, scd_version, TO_DATE(a.change_date) as scd_start_date, TO_DATE(a.end_date) as scd_end_date | ||
WHERE a.id_lead = a.customer_id; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.