HBase數據模型深刻剖析-OLAP商業環境實戰

本套系列博客從真實商業環境抽取案例進行總結和分享,並給出Spark源碼解讀及商業實戰指導,請持續關注本套博客。版權聲明:本套Spark源碼解讀及商業實戰歸做者(秦凱新)全部,禁止轉載,歡迎學習。app

1:用戶使用過哪些APP和使用時長(以用戶id, 天爲單位)

週期內時長統計學習

table-->behavior_user_app_201809
rowKey-->userid:20180904
columnfamily-->timeLen
column --> appName (包名爲多個) 
value --> long值  

String tableName = "behavior_user_app_" + DateUtils.getMonthByHour(model.getHour());
Table table = HBaseClient.getInstance(this.props).getTable(tableName);
String rowKey = model.getUserId()+":"+DateUtils.getDayByHour(model.getHour());
table.incrementColumnValue(Bytes.toBytes(rowKey), Bytes.toBytes("timeLen"), Bytes.toBytes(model.getPackageName()), model.getTimeLen());
複製代碼

2:用戶每小時的使用應用的時長(以用戶id,天爲單位)

一天中不一樣時段的玩機趨勢this

table-->behavior_user_hour_time_201809
rowKey-->userid:20180904
columnfamily-->timeLen
column --> 12 13 14 ... ...(小時24個) 
value --> long值 

String tableName = "behavior_user_hour_time_" + DateUtils.getMonthByHour(model.getHour());
Table table = HBaseClient.getInstance(this.props).getTable(tableName);
String rowKey = model.getUserId()+":"+DateUtils.getDayByHour(model.getHour());
table.incrementColumnValue(Bytes.toBytes(rowKey), Bytes.toBytes("timeLen"), Bytes.toBytes(DateUtils.getOnlyHourByHour(model.getHour())), model.getTimeLen());
複製代碼

3:用戶天天的玩機時長(以用戶id爲單位)

一個月中不一樣天數的玩機趨勢spa

table-->behavior_user_day_time_201809
rowKey-->userid
columnfamily-->timeLen
column --> 1 2 3 ... ...(天數:31) 
value --> long值 

String tableName = "behavior_user_day_time_" + DateUtils.getMonthByHour(model.getHour());
Table table = HBaseClient.getInstance(this.props).getTable(tableName);
String rowKey = String.valueOf(model.getUserId());
table.incrementColumnValue(Bytes.toBytes(rowKey), Bytes.toBytes("timeLen"), Bytes.toBytes(DateUtils.getOnlyDayByHour(model.getHour())), model.getTimeLen());
複製代碼

4:用戶每一個應用每小時的玩機時長(以用戶id,天,應用爲單位)

table-->behavior_user_day_app_time_201809
rowKey-->userid:day:packageName
columnfamily-->timeLen
column --> 12 13 14 ... ...(小時24個)
value --> long值 

String tableName = "behavior_user_day_app_time_" + DateUtils.getMonthByHour(model.getHour());
Table table = HBaseClient.getInstance(this.props).getTable(tableName);
String rowKey = model.getUserId()+":"+DateUtils.getDayByHour(model.getHour())+":"+model.getPackageName();

table.incrementColumnValue(Bytes.toBytes(rowKey), Bytes.toBytes("timeLen"), Bytes.toBytes(DateUtils.getOnlyHourByHour(model.getHour())), model.getTimeLen());
複製代碼

5:用戶每一個應用天天的玩機時長(以用戶id,應用爲單位)

table-->behavior_user_day_time_201809
rowKey-->userid:packageName
columnfamily-->timeLen
column --> 1 2 3 ... ...(天數:31) 
value --> long值 


String tableName = "behavior_user_day_app_time_" + DateUtils.getMonthByHour(model.getHour());
Table table = HBaseClient.getInstance(this.props).getTable(tableName);
String rowKey = model.getUserId()+":"+model.getPackageName();

table.incrementColumnValue(Bytes.toBytes(rowKey), Bytes.toBytes("timeLen"), Bytes.toBytes(DateUtils.getOnlyDayByHour(model.getHour())), model.getTimeLen());
複製代碼

6:總結

秦凱新 於深圳code

相關文章
相關標籤/搜索