码迷,mamicode.com
首页 > 其他好文 > 详细

dwt_user_topic

时间:2021-02-26 13:12:24      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:tor   bsp   ext   compress   ESS   次数   sele   join   fir   

用户主题宽表

类似累积事实表

drop table if exists dwt_user_topic; 
create external table dwt_user_topic 
( 
user_id string comment ‘用户 id‘, 
login_date_first string comment ‘首次登录时间‘, 
login_date_last string comment ‘末次登录时间‘, 
login_count bigint comment ‘累积登录天数‘, 
login_last_30d_count bigint comment ‘最近 30 日登录天数‘, 
order_date_first string comment ‘首次下单时间‘, 
order_date_last string comment ‘末次下单时间‘, 
order_count bigint comment ‘累积下单次数‘, 
order_amount decimal(16,2) comment ‘累积下单金额‘, 
order_last_30d_count bigint comment ‘最近 30 日下单次数‘, 
order_last_30d_amount bigint comment ‘最近 30 日下单金额‘, 
payment_date_first string comment ‘首次支付时间‘, 
payment_date_last string comment ‘末次支付时间‘, 
payment_count decimal(16,2) comment ‘累积支付次数‘, 
payment_amount decimal(16,2) comment ‘累积支付金额‘, 
payment_last_30d_count decimal(16,2) comment ‘最近 30 日支付次数‘, 
payment_last_30d_amount decimal(16,2) comment ‘最近 30 日支付金额‘ 
)
COMMENT ‘用户主题宽表‘ 
stored as parquet 
location ‘/ecdw/dwt/dwt_user_topic/‘ 
tblproperties ("parquet.compression"="lzo");


--插入
insert overwrite table dwt_user_topic 
select 
    nvl(new.user_id,old.user_id), 
    if(old.login_date_first is null and new.login_count>0,‘2020-03-10‘,old.login_date_first), 
    if(new.login_count>0,‘2020-03-10‘,old.login_date_last), 
    nvl(old.login_count,0)+if(new.login_count>0,1,0), 
    nvl(new.login_last_30d_count,0), 
    if(old.order_date_first is null and new.order_count>0,‘2020-03-10‘,old.order_date_first),
    if(new.order_count>0,‘2020-03-10‘,old.order_date_last), 
    nvl(old.order_count,0)+nvl(new.order_count,0), 
    nvl(old.order_amount,0)+nvl(new.order_amount,0), 
    nvl(new.order_last_30d_count,0), 
    nvl(new.order_last_30d_amount,0), 
    if(old.payment_date_first is null and new.payment_count>0,‘2020-03-10‘,old.payment_date_first), 
    if(new.payment_count>0,‘2020-03-10‘,old.payment_date_last), 
    nvl(old.payment_count,0)+nvl(new.payment_count,0), 
    nvl(old.payment_amount,0)+nvl(new.payment_amount,0), 
    nvl(new.payment_last_30d_count,0), 
    nvl(new.payment_last_30d_amount,0) 
from dwt_user_topic old 

full outer join 
( 
select 
    user_id, 
    sum(if(dt=‘2020-03-10‘,login_count,0)) login_count,   -- 获取最新的会员信息
    sum(if(dt=‘2020-03-10‘,order_count,0)) order_count, 
    sum(if(dt=‘2020-03-10‘,order_amount,0)) order_amount, 
    sum(if(dt=‘2020-03-10‘,payment_count,0)) payment_count, 
    sum(if(dt=‘2020-03-10‘,payment_amount,0)) payment_amount, 
    sum(if(login_count>0,1,0)) login_last_30d_count,   -- 获取累积30天的会员信息 
    sum(order_count) order_last_30d_count, 
    sum(order_amount) order_last_30d_amount, 
    sum(payment_count) payment_last_30d_count, 
    sum(payment_amount) payment_last_30d_amount 
from dws_user_action_daycount 
where dt>=date_add( ‘2020-03-10‘,-30) 
group by user_id 
)new 
on old.user_id=new.user_id;

 

dwt_user_topic

标签:tor   bsp   ext   compress   ESS   次数   sele   join   fir   

原文地址:https://www.cnblogs.com/ldy233/p/14448831.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!