##hive 双表合并生成新主键
insert overwrite into dim_goods_d partition(dt='2018-06-01')
select
tb.*,
row_number() over(order by id) + ta.max_id as gid
from tmp_s_inc as tb
cross join
(select coalesce(max(gid),0)) as max_id from dim_goods_d where dt='2018-05-31') ta
union all
select * from dim_goods_d where dt='2018-05-31'
=========事实表装载代理键,没有把代理键引入事实表中会让sql查询极为复杂(维度表慎用拉链表,代理键会造成整个开发复杂度的增加)===========================
fact_order(事实表) oid(订单ID) tm_id(时间ID)...(后面还有很多事实字段)
dim_user(维度表,拉链表--缓慢纬度建模) uid(代理ID) id(数据表ID) name dept,start_date,end_date,... (要把这个维度表的代理键装载到事实表中)
order(业务表) oid(代理ID),id(数据表ID),created_time,updated_time
-----query where created_time > '2018-06-01' ---->order_inc 采集进新增数据select
select
ta.*,uid
--order的增量表
order_incas ta
join
--(id关联上说明是同一个条数据,表中可能存在一个ID多条一样的,新增数据要大于维度表开始时间且时间应该小于这个数据的业务结束时间默认9999,拉链表只要这个业务时间没结束会替换成9999)
dim_user as tb on ta.id=tb.id and ta.created_time >=tb.start_date and ta.created_time <= tb.end_date
---hive中由于不支持不等号join方式,于是需要用嵌套方法
select * from (
select
ta.*,uid
--order的增量表
order_incas ta
join
--(id关联上说明是同一个条数据,表中可能存在一个ID多条一样的,新增数据要大于维度表开始时间且时间应该小于这个数据的业务结束时间默认9999,拉链表只要这个业务时间没结束会替换成9999)
dim_user as tb on ta.id=tb.id) tt where ta.created_time >=tb.start_date and ta.created_time <= tb.end_date