当前位置: 首页 > article >正文

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

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}')
select
     user_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
(
    select
         user_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_flg
    from
    (
        select
             user_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_time
        from table_name_inc_d--增量表
        where pt_d='${hiveconf:pt_d}'
        group by
             user_id
            ,country
            ,magic_ui_version
            ,device_type
            ,starting_source
 
        union all
    
        select
             user_id
            ,country
            ,magic_ui_version
            ,device_type
            ,starting_source
            ,'0'                                                    as today_active_flg
            ,user_active_365_flg
            ,first_event_time
            ,last_event_time
        from table_name_all_d--全量表
        where pt_d='${hiveconf:last_day}'
    )t1
    group by
         user_id
        ,country
        ,magic_ui_version
        ,device_type
        ,starting_source
)t2
;

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


http://www.kler.cn/news/288876.html

相关文章:

  • 设计模式 17 中介者模式
  • Spring优缺点和SpringBoot基础和搭建
  • 数据库系统 第31节 物理存储与文件系统
  • 奇安信天眼--探针/分析平台部署及联动
  • MySQL5.7配置优化
  • h5适配iOS——window.open失效
  • 搭建pypi私有仓库(局域网内)出现的一些问题及解决方法
  • 【数据库|第11期】深入掌握 SQL Server、Access 与 SQLite 中的 `UNION` 与 `UNION ALL`:从理论到实践
  • windows系统安装配置Apache Maven
  • React16新手教程记录
  • org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
  • 晋升路上的梦想之光,社科院与杜兰大学金融管理硕士助力你前行
  • 数造科技荣登“科创杯”领奖台,开启数据驱动新篇章!
  • HarmonyOS实战开发:NAPI接口规范开发
  • Centos根目录扩容Docker分区扩容最佳实践
  • 【网络安全】Collabora在线存储型XSS(CVE-2024-29182)+代码审计
  • OpenCV 图像处理应用实战算法列表汇总(长期更新)
  • Redis安装+常用命令合集大全+Redis Desktop Manager
  • 黑悟空!一区预定!原创首发!SLWCHOA-Transformer-LSTM混合改进策略的黑猩猩优化算法多变量时间序列预测
  • FPGA速度优化
  • sickos 靶机渗透(wolf cms 渗透,squid 代理)
  • 【软件造价咨询】AI大模型能不能替代软件工程造价师完成软件造价?
  • RabbitMQ和Kafka的区别
  • python-A-B数对
  • WPF MVVM如何在ViewModel直接操作控件对象
  • 【数学建模国赛思路预约】2024高教社杯全国大学生数学建模竞赛助攻——思路、可运行代码、成品参考
  • 【数据结构】Set的使用与注意事项
  • 正则表达式实现括号替换
  • 【机器学习】CNN在计算机视觉中的应用
  • 数学建模学习(130):神经网络预测—模型选择与实战案例解析