日新 日活使用者統計hql開發

2021-10-01 16:10:40 字數 3024 閱讀 3345

1.建立乙個表,來儲存每天新增的資料(分割槽表)

2.統計每天的活躍使用者(日活)(需要使用者的ip,使用者的賬號,使用者訪問的時間最早的一條url和時間)

3.統計每天的新增使用者(日新)

1.建表對映日誌資料

create

table t_web_log(ip string,url string,

time string,uid string)

partitioned by

(day string)

row format delimited fields

terminated

by','

;load

data

local inpath '/root/hivetest/access.log.0804'

into

table t_web_log partitionby(

day=

'20190804'

);

2.每日活躍使用者

select ip,url,

time

,uid

from

(select ip,url,

time

,uid,

row_number(

)over

(partition

by uid order

bytime

desc

)as rn

from t_web_log

where

day=

'20190804'

) tmp

where rn=1;

--建表儲存日活資料

create

table t_user_active_day(ip string,url string,first_time string,uid string)

partitioned by

(day string)

;--將資料匯入表t_user_active_day中

簡單思路:

1.將當日活躍使用者跟歷史使用者表關聯,找出那些在歷史使用者表中尚不存在的使用者–新使用者(uid)

2.將新使用者插入歷史使用者表

建表:1.歷史使用者表(uid)

2.新使用者表(like 活躍使用者表)

--step 1:

insert

into

table t_user_new partition

(day

='20190806'

)select ip,url,first_time,uid

from

(select a.ip,a.url,a.first_time,a.uid,b.uid as newid

from t_user_active_day a left

join t_user_history b

on a.uid=b.uid

where a.

day=

'20190806'

) tmp

where newid is

null

;--step 2:

insert

into

table t_user_history partition

(day

='20190806'

)select uid

from t_user_new

where

day=

'20190806'

;

shell中獲取日期的各種格式

#!/bin/bash

day_str=`date -d last-day +

%y%m%d`

echo

"正在準備處理 $day_str 的資料"

hive_exec=/usr/local/src/hive-1.2.1/bin/hive

hql_user_active_day="

insert into table t_user_active_day partition(day=$day_str)

select ip,url,time,uid

from

(select ip,url,time,uid,

row_number() over(partition by uid order by time desc) as rn

from t_web_log

where day=$day_str) tmp

where rn=1;

"$hive_exec

-e "$hql_user_active_day"

hql_user_new_day="

insert into table t_user_new partition(day=$day_str)

select ip,url,first_time,uid

from

(select a.ip,a.url,a.first_time,a.uid,b.uid as newid

from t_user_active_day a left join t_user_history b

on a.uid=b.uid

where a.day=$day_str) tmp

where newid is null;

"$hive_exec

-e "$hql_user_new_day"

hql_user_history="

insert into table t_user_history partition(day=$day_str)

select uid

from t_user_new

where day=$day_str;

"$hive_exec

-e "$hql_user_history"

注:hive表中的預設分隔符為『-001』

松果生活使用者調研

這個作業屬於哪個課程 2019學年02學期單紅老師軟體工程實踐 這個作業要求在 個人作業 軟體評測 團隊名稱 松果星球委員會 這個作業的目標 作業正文 本博文其他參考文獻 相關部落格 構建之法 學號姓名 221701311 李昊朋221701129 龔俊鵬221701433 賴曉輝221701410...

mysql統計使用者留存 SQL 統計使用者留存

問題描述 有乙個用來記錄每日客戶消耗資料的表 t,它的表結構如下 要求 統計出頭部客戶 腰部客戶 尾部客戶在上個月 2020 06 01 2020 06 30 的留存情況。輸出結果的格式 資料定義 頭部客戶 上個月消耗金額大於等於 30000 的客戶 腰部客戶 上個月消耗金額在 10000 3000...

公尺讀 累計服務近2億使用者 日活使用者近1000萬

techweb 9月8日訊息,趣頭條旗下網路文學產品公尺讀對外披露,目前已累計服務近兩億使用者,日活躍使用者近1000萬,使用者日均使用時長長期穩定在2小時左右。從使用者性別上看,公尺讀的受眾分布均衡,男性使用者與女性使用者佔比基本持平,覆蓋了22歲以下到60歲幾乎全年齡段使用者,其中23 40歲使...