18 友盟项目--统计---日活、周活、月活--创建表并插入选择出的数据
定位分区-->with cube维度组合 --> 去null过滤 --->
日活跃用户
spark执行代码 --- 调用工具类
执行sql工具类:ExecSQLUtil
public class StatDayActJava{ public static void main(String[] args) throw Exception{ SparkConf conf = new SparkConf(); conf.setAppName("statNew"); conf.setMaster("local[4]"); //spark链接 SparkSession sess = SparkSession.builder().config(conf).enableHiveSupport().getOrCreate(); //注册执函数 ExecSQLUtil.execRegisterFuncs(sess); //执行sql ExecSQLUtil.execSQLScript(sess, "stat_act_day.sql"); } }
日活跃量 sql语句 启动日志下appstartuplogs
stat_act_day.sql

use big12_umeng ; create table if not exists stat_act_day( day string , appid string, appplatform string, brand string , devicestyle string, ostype string , appversion string , cnt int ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' lines terminated by '\n'; insert overwrite table stat_act_day select formatbyday(-5, 'yyyyMMdd'), tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion , count(tt.deviceid) FROM ( select t.appid , t.appplatform, t.brand , t.devicestyle, t.ostype , t.appversion , t.deviceid FROM ( select appid , appplatform, brand , devicestyle, ostype , appversion , deviceid from appstartuplogs WHERE concat(ym,day) = formatbyday(-5, 'yyyyMMdd') group BY appid , appplatform, brand , devicestyle, ostype , appversion, deviceid with cube )t where t.appid is not null and t.deviceid is not null )tt group BY tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion order by tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion
周活跃量---每天算本周活跃
concat() 连接函数
返回结果为连接参数产生的字符串
stat_act_week.sql

use big12_umeng ; create table if not exists stat_act_week( day string , appid string, appplatform string, brand string , devicestyle string, ostype string , appversion string , cnt int ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' lines terminated by '\n'; insert overwrite table stat_act_week select formatbyday(-5, 'yyyyMMdd'), tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion , count(tt.deviceid) FROM ( select t.appid , t.appplatform, t.brand , t.devicestyle, t.ostype , t.appversion , t.deviceid FROM ( select appid , appplatform, brand , devicestyle, ostype , appversion , deviceid from appstartuplogs WHERE formatbyweek(concat(ym,day) , 'yyyyMMdd' , 0 , 'yyyyMMdd') = formatbyweek(-1 , 'yyyyMMdd') group BY appid , appplatform, brand , devicestyle, ostype , appversion, deviceid with cube )t where t.appid is not null and t.deviceid is not null )tt group BY tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion order by tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion
月活跃量
stat_act_month.sql

use big12_umeng ; create table if not exists stat_act_month( month string , appid string, appplatform string, brand string , devicestyle string, ostype string , appversion string , cnt int ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' lines terminated by '\n'; insert into table stat_act_month select '${ym}' , tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion , count(tt.deviceid) FROM ( select t.appid , t.appplatform, t.brand , t.devicestyle, t.ostype , t.appversion , t.deviceid FROM ( select appid , appplatform, brand , devicestyle, ostype , appversion , deviceid from appstartuplogs WHERE ym = '${ym}' group BY appid , appplatform, brand , devicestyle, ostype , appversion, deviceid with cube )t where t.appid is not null and t.deviceid is not null )tt group BY tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion order by tt.appid , tt.appplatform, tt.brand , tt.devicestyle, tt.ostype , tt.appversion
分类:
大数据项目
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下