天天都有数据导入分区,不可能手动把数据导入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;