原创

Data Vault初探(四) —— 初始装载

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://wxy0327.blog.csdn.net/article/details/50222361

下面的SQL脚本用于完成Data Vault的初始装载过程。

USE dv;  
  
SET AUTOCOMMIT = 0;  
  
-- 清空附属表、链接表、中心表  
SET FOREIGN_KEY_CHECKS=0;  
TRUNCATE sat_customer;  
TRUNCATE sat_order_product;  
TRUNCATE sat_product;  
TRUNCATE sat_product_catagory;  
TRUNCATE sat_sales_order;  
TRUNCATE link_order_customer;  
TRUNCATE link_order_product;  
TRUNCATE link_product_catagory;  
TRUNCATE hub_product_catagory;  
TRUNCATE hub_customer;  
TRUNCATE hub_product;  
TRUNCATE hub_sales_order;  
SET FOREIGN_KEY_CHECKS=1;  
  
START TRANSACTION;  
  
-- 装载中心表  
insert into hub_product_catagory (product_catagory_id,record_source)  
select product_catagory_id,'product_catagory' from product_catagory;  
  
insert into hub_customer (customer_id,record_source)  
select customer_id,'customer' from customer;  
  
insert into hub_product (product_id,record_source)  
select product_id,'product' from product;  
  
insert into hub_sales_order (sales_order_id,record_source)  
select sales_order_id,'sales_order' from sales_order;  
  
-- 装载链接表  
insert into link_order_customer (hub_sales_order_id,hub_customer_id,record_source)  
select hub_sales_order_id,hub_customer_id,'hub_sales_order,sales_order,hub_customer,customer'  
from hub_sales_order,sales_order,hub_customer,customer  
where hub_sales_order.sales_order_id = sales_order.sales_order_id  
  and hub_customer.customer_id = customer.customer_id  
  and sales_order.customer_id = customer.customer_id;  
  
insert into link_order_product (hub_sales_order_id,hub_product_id,record_source)  
select hub_sales_order_id,hub_product_id,'hub_sales_order,hub_product,sales_order_item'  
from hub_sales_order,hub_product,sales_order_item  
where hub_sales_order.sales_order_id = sales_order_item.sales_order_id  
  and hub_product.product_id = sales_order_item.product_id;  
    
insert into link_product_catagory (hub_product_id,hub_product_catagory_id,record_source)  
select hub_product_id,hub_product_catagory_id,'hub_product,product,hub_product_catagory'  
from hub_product,product,hub_product_catagory
where hub_product.product_id = product.product_id  
  and hub_product_catagory.product_catagory_id = product.product_catagory_id;  
    
-- 装载附属表  
insert into sat_customer   
(hub_customer_id,  
load_end_dts,  
record_source,  
customer_name,  
city_name,  
province_name,  
cust_post_code,  
cust_address,  
ship_post_code,  
ship_address)  
select   
hub_customer_id,  
'2200-01-01',  
'hub_customer,customer,city,province',  
customer.customer_name,  
city.city_name,  
province.province_name,  
customer.cust_post_code,  
customer.cust_address,  
customer.ship_post_code,  
customer.ship_address  
from hub_customer,customer,city,province  
where hub_customer.customer_id = customer.customer_id  
  and customer.city_id = city.city_id  
  and city.city_id = province.province_id;  
    
insert into sat_order_product   
(link_order_product_id,  
load_end_dts,  
record_source,  
unit_price,  
quantity  
)  
select   
link_order_product_id,  
'2200-01-01',  
'link_order_product,hub_sales_order,hub_product,sales_order_item',  
sales_order_item.unit_price,  
sales_order_item.quantity  
from link_order_product,hub_sales_order,hub_product,sales_order_item  
where link_order_product.hub_sales_order_id = hub_sales_order.hub_sales_order_id  
  and link_order_product.hub_product_id = hub_product.hub_product_id  
  and sales_order_item.sales_order_id = hub_sales_order.sales_order_id  
  and sales_order_item.product_id = hub_product.product_id;  
    
insert into sat_product  
(hub_product_id,  
load_end_dts,  
record_source,  
product_name,  
unit_price  
)  
select   
hub_product_id,  
'2200-01-01',  
'hub_product,product',  
product.product_name,  
product.unit_price  
from hub_product,product  
where hub_product.product_id = product.product_id;  
  
insert into sat_product_catagory  
(hub_product_catagory_id,  
load_end_dts,  
record_source,  
product_catagory_name  
)  
select   
hub_product_catagory_id,  
'2200-01-01',  
'hub_product_catagory,product_catagory',  
product_catagory.product_catagory_name  
from hub_product_catagory,product_catagory  
where hub_product_catagory.product_catagory_id = product_catagory.product_catagory_id;  
  
insert into sat_sales_order  
(hub_sales_order_id,  
load_end_dts,  
record_source,  
order_time,  
entry_time,  
amount,  
allocate_time,  
packing_time,  
ship_time,  
receive_time  
)  
select   
hub_sales_order_id,  
'2200-01-01',  
'hub_sales_order,sales_order',  
sales_order.order_time,  
sales_order.entry_time,  
sales_order.amount,  
sales_order.allocate_time,  
sales_order.packing_time,  
sales_order.ship_time,  
sales_order.receive_time  
from hub_sales_order,sales_order  
where hub_sales_order.sales_order_id = sales_order.sales_order_id;  
  
COMMIT; 

下面是用Kettle完成初始装载的作业和步骤。






























文章最后发布于: 2015-12-08 18:27:03
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览