天天都有數據導入分區,不可能手動把數據導入hive中,須要寫一個shell腳本load_ods_table.shweb
load_ods_table.sh腳本:正則表達式
接下來作ETLsql
drop table ods_weblog_detail; create table ods_weblog_detail( valid string, --有效標識 remote_addr string, --來源IP remote_user string, --用戶標識 time_local string, --訪問完整時間 daystr string, --訪問日期 timestr string, --訪問時間 month string, --訪問月 day string, --訪問日 hour string, --訪問時 request string, --請求的url status string, --響應碼 body_bytes_sent string, --傳輸字節數 http_referer string, --來源url ref_host string, --來源的host ref_path string, --來源的路徑 ref_query string, --來源參數query ref_query_id string, --來源參數query的值 http_user_agent string --客戶終端標識 ) partitioned by(datestr string);
在切分url時候,能夠採用正則表達式,或者一個函數shell
函數:parse_url_tuple數組
傳入url爲:http_referer,把引號替換空,獲得一個乾淨的url,而後在調用函數,函數
而後解析出host、path、query、queryidurl
as 後面爲別名spa
parse得出的是一個數組,要把數組變成多個字段,就須要lateral view,就能夠把數組當作爲多個字段,相似於轉置行轉列3d
a.*爲爲原來表的全部字段code
b.*爲得出的數組
可使用sql寫一個腳本
etl_detail腳本
導入數據可能出現錯誤,會致使抽取的數據錯誤影響統計結果,由於運行時候不是報錯,須要取排查
能夠是寫個腳本取查看某個字段誤差的較大,就應該取檢查
有個環節叫作數據質量檢查,寫shell腳本,檢查一些特定的表,好比正數出現負數,增加的出現減小這種明顯錯誤
計算該處理批次(一天)中的各小時pvs
create tables dw_pvs_hour( month string,day string,hour string,pvs bigint )partitiined by (datestr string);
show tables;
insert into table shizhan.dw_pvs_hour partitioned (datestr='2013-9-18')
seletc a.month as month,a.day as day,a.hour as hour ,count(1) as pvs from ods_weblog_detail a
where a.datestr='2013-9-18' group by a.month,a.day,a.hour;
按小時粒度統計各來訪域名的產生的pv數並排序
大體理解結果爲下圖:
create table dw_ref_host_visit_cnts_h(ref_host string,month string,day string,hour string,ref_host_cnts bigint);建立表
insert into table dw_ref_host_visit_cnts_h partitioned (datestr=''2013-9-18);插入分區2013-9-18數據
select ref_host,month,day,hour,count(1) as ref_host_cnt 選擇域名,月日時,記錄數
from ods_weblog_detail
group by ref_host,month,day,hour
having ref_host is not null
order by hour asc,day asc,month acs,ref_hour_cnts desc;
查詢出結果以下:
seletc * from dw_ref_host_visit_cnts_h limit 10;
接下來只須要把每一個小時的域名點擊量進行排序,至關於加一個尾列
select ref_host,ref_host_cnts,concat(month,day,hour),row_number() over(partiton by concat(month,day,hour) order by ref_host_cnts desc) as od
from dw_ref_host_visit_cnts_h
concat函數爲把month,day,hour鏈接在一塊兒
按照concat分區,把每一個分區按照點擊次數降序加入尾列
根據上述row_number的功能,可編寫Hql取各小時的ref_host訪問次數topn
insert into table zs. dw_pvs_refhost_topn partiton(datestr='2013-9-18')
select t.hour,t.od,t.ref_host,t.ref_host_cnts.
from (
seletc ref_host,ref_host_cnts,concat(month,day,hour),row_number() over(partiton by concat(month,day,hour) order by ,ref_host_cnts desc) as od
from dw_ref_host_visit_cnts_h
) t where od<=3;