利用较大时间范围增量表制作快照时的一种夜间生产优化方式

当我们在利用大量增量表中的数据加工快照表时,往往需要在集市层的大宽表中扫描较大时间范围内的数据,
但有一种用于夜间生产的优化思路,可以不必扫描整张增量大宽表,
而是通过利用前一天该表的快照当天的增量数据进行union,来完成当天的生产。

优化前

可以看到我们要取得每天所有用户的最新下单时间来制作快照,从增量交易大宽表中扫描了所有的历史交易订单

select
    id1,
    id2,
    max(last_trade_date) as last_trade_date,
    '$now.date' as partition_date
from (
-- 增量数据使用 T-2日数据和T-1日增量合并,减少数据加工时间
select 
    t1.id1 as id1,
    t2.id2 as id2,
    t2.partition_date as last_trade_date
from table_id1_list t1
inner join cashier_pay_inc t2
on t1.partition_date = t2.partition_date
and t1.order_id = t2.order_id
where t1.partition_date <= '$now.date'
and t2.is_suc = 1
group by t1.id1,t2.id2,t2.partition_date
)
group by id1,id2

优化后

夜间生产快照表时,可以通过将调用自身前一天的快照,与当天增量数据合并的方式,极大减少数据加工时间

select
    id1,
    id2,
    max(last_trade_date) as last_trade_date,
    '$now.date' as partition_date
from (
-- 增量数据使用 T-2日数据和T-1日增量合并,减少数据加工时间
select id1,id2,last_trade_date as last_trade_date
from table_id1_ss 
where partition_date = '$now.delta(1).date'
union all 
select 
    t1.id1 as id1,
    t2.id2 as id2,
    t2.partition_date as last_trade_date
from id2 t1
inner join cashier_pay_inc t2
on t1.partition_date = t2.partition_date
and t1.order_id = t2.order_id
where t1.partition_date = '$now.date'
and t2.is_suc = 1
group by t1.id1,t2.id2,t2.partition_date
)
group by id1,id2
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值