当前位置: 首页> 教育> 培训 > HiveQL如何统计用户近一段时间活跃标签

HiveQL如何统计用户近一段时间活跃标签

时间:2025/7/12 15:47:09来源:https://blog.csdn.net/weixin_43451620/article/details/141713016 浏览次数:0次
create table if not exists schema_name.table_name
(user_id                            string comment '用户id',country                            string comment '国家',magic_ui_version                   string comment 'magic版本',device_type                        string comment '机型',starting_source                    string comment '启动来源',today_active_flg                   string comment '今日活跃标识(1活跃0:未活跃)',first_event_time                   string comment '用户首次活跃时间',last_event_time                    string comment '用户末次活跃时间',user_active_365_flg                string comment '用户365活跃标志',active_retention_2d_flg            string comment '活跃用户次日留存标识'
)comment '用户365活跃日表'
partitioned by (pt_d  string  comment '天分区')
row format delimited
fields terminated by '\001'
lines terminated by '\n'
stored as orc
;insert overwrite table schema_name.table_name
partition (pt_d = '${hiveconf:pt_d}')
selectuser_id,country,magic_ui_version,device_type,starting_source,today_active_flg,first_event_time,last_event_time,user_active_365_flg,if(substring(user_active_365_flg,2,1)='1',1,0)              as active_retention_2d_flg
from
(selectuser_id,country,magic_ui_version,device_type,starting_source,max(today_active_flg)                                                              as today_active_flg,min(first_event_time)                                                              as first_event_time,max(last_event_time)                                                               as last_event_time,concat(max(today_active_flg),substr(max(user_active_365_flg),1,364))               as user_active_365_flgfrom(selectuser_id,country,magic_ui_version,device_type,starting_source,'1'                                                                            as today_active_flg,rpad('',365,'0')                                                               as user_active_365_flg,'${hiveconf:pt_d}'                                                             as first_event_time,'${hiveconf:pt_d}'                                                             as last_event_timefrom table_name_inc_d--增量表where pt_d='${hiveconf:pt_d}'group byuser_id,country,magic_ui_version,device_type,starting_sourceunion allselectuser_id,country,magic_ui_version,device_type,starting_source,'0'                                                    as today_active_flg,user_active_365_flg,first_event_time,last_event_timefrom table_name_all_d--全量表where pt_d='${hiveconf:last_day}')t1group byuser_id,country,magic_ui_version,device_type,starting_source
)t2
;

通过设计一张全量数据累积模型,给用户打上活跃标签。可基于用户活跃标签数据模型,有效提高用户活跃相关标签计算性能

关键字:HiveQL如何统计用户近一段时间活跃标签

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: