需求六:应用闪退相关指标
原创大约 2 分钟
实现思路
因为
每日Android系统不同APP版本闪退数
和每日IOS系统不同APP版本闪退数
这两个指标,其实是对每日设备平台闪退总计
指标的扩展。使用
DWD层
的dwd_app_collapse
表进行统计,但要依据platform
和code
进行分组,将聚合结果保存到DWS层
的dws_app_collapse_all
表中。然后再基于
dws_app_collapse_all
表就可以统计出这三个指标了。最后,将统计结果保存在
APP层
对应的表中,对应的表名如下。每日设备平台闪退总计
::app_app_collapse_all
。每日Android系统不同APP版本闪退数
:app_app_collapse_android
。每日IOS系统不同APP版本闪退数
:app_app_collapse_ios
。
DWS层开发
根据实现思路,需要在DWS层
初始化对应的dws_app_collapse_all
表。
> cd /home/work/warehouse_user_action
> vi dws_shopmall_requirement06_init.sh
#!/bin/bash
# 需求六:应用闪退相关指标
# dws层数据库和表初始化,只需要执行一次
hive -e "
create database if not exists dws_shopmall;
create external table if not exists dws_shopmall.dws_app_collapse_all (
platform string,
code string,
num int
) partitioned by(dt string)
row format delimited
fields terminated by '\t'
location 'hdfs://server01:9000/data/dws/app_collapse_all';
"
再来给它添加分区。
> cd /home/work/warehouse_user_action
> vi dws_shopmall_requirement06_add_partition.sh
#!/bin/bash
# 需求六:应用闪退相关指标
# 每天凌晨执行一次
if [ "d$1" = "d" ]
then
dt=`date +%Y%m%d --date="1 days ago"`
else
dt=$1
fi
hive -e "
insert overwrite table dws_shopmall.dws_app_collapse_all partition(dt='${dt}') select
platform,
code,
count(*) as num
from dwd_shopmall.dwd_app_collapse
where dt = '${dt}' and platform in (1,2)
group by platform, code;
"
可以通过定时任务来执行它。
> crontab -e
# 每天凌晨0点1分执行
1 0 * * * /home/work/warehouse_user_action/dws_shopmall_requirement06_add_partition.sh
APP层开发
在APP层
初始化对应的结果表。
#!/bin/bash
# 需求六:应用闪退相关指标
# app层数据库和表初始化,只需要执行一次
hive -e "
create database if not exists app_shopmall;
create external table if not exists app_shopmall.app_app_collapse_all (
clazz string,
num int
) partitioned by(dt string)
row format delimited
fields terminated by '\t'
location 'hdfs://server01:9000/data/app/app_collapse_all';
create external table if not exists app_shopmall.app_app_collapse_android (
clazz string,
num int
) partitioned by(dt string)
row format delimited
fields terminated by '\t'
location 'hdfs://server01:9000/data/app/app_collapse_android';
create external table if not exists app_shopmall.app_app_collapse_ios (
clazz string,
num int
) partitioned by(dt string)
row format delimited
fields terminated by '\t'
location 'hdfs://server01:9000/data/app/app_collapse_ios';
"
再来给它添加分区。
> cd /home/work/warehouse_user_action
> vi app_shopmall_requirement06_add_partition.sh
#!/bin/bash
# 需求六:应用闪退相关指标
# 每天凌晨执行一次
if [ "d$1" = "d" ]
then
dt=`date +%Y%m%d --date="1 days ago"`
else
dt=$1
fi
hive -e "
insert overwrite table app_shopmall.app_app_collapse_all partition(dt='${dt}') select
case platform
when 1 then 'android'
when 2 then 'ios'
end clazz,
sum(num) as num
from dws_shopmall.dws_app_collapse_all
where dt = '${dt}'
group by platform;
insert overwrite table app_shopmall.app_app_collapse_android partition(dt='${dt}') select
vercode as clazz,
sum(num) as num
from dws_shopmall.dws_app_collapse_all
where dt = '${dt}' and platform = 1
group by code;
insert overwrite table app_shopmall.app_app_collapse_ios partition(dt='${dt}') select
vercode as clazz,
sum(num) as num
from dws_shopmall.dws_app_collapse_all
where dt = '${dt}' and platform = 2
group by code;
"
可以通过定时任务来执行它。
> crontab -e
# 每天凌晨0点1分执行
1 0 * * * /home/work/warehouse_user_action/app_shopmall_requirement06_add_partition.sh
感谢支持
更多内容,请移步《超级个体》。