date转换成string hive_Hive分析统计离线日志信息

承接上一篇文档《新增访客数量MR统计之MR数据输出到MySQL》

hive-1.2.1的版本可以直接映射HBase已经存在的表

如果说想在hive创建表,同时HBase不存在对应的表,也想做映射,那么采用编译后的hive版本hive-1.2.1-hbase

1. Hive中创建外部表,关联hbase

CREATE EXTERNAL TABLE event_log_20180728(key string,pl string,ver string,s_time string,u_ud string,u_sd string,en string)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:pl,info:ver,info:s_time,info:u_ud,info:u_sd,info:en")TBLPROPERTIES("hbase.table.name" = "event_log_20180728");
54e11d6a3111b5ed89630dce81bc39c3.png

统计多少个新用户:

select count(*) from event_log_20180728 where en="e_l";
acf5ad2ee7ad764bf86ac437f0c1ff50.png
f5a924b2b5c69c80277036df955c3dbd.png

2. 提取数据,进行初步的数据过滤操作,最终将数据保存到临时表

创建临时表

CREATE TABLE stats_hourly_tmp01(pl string,ver string,s_time string,u_ud string,u_sd string,en string,`date` string,hour int);
c6ac1fe32c58cbe44248713589be01ca.png

将原始数据提取到临时表中

INSERT OVERWRITE TABLE stats_hourly_tmp01SELECT pl,ver,s_time,u_ud,u_sd,en,from_unixtime(cast(s_time/1000 as int),'yyyy-MM-dd'), hour(from_unixtime(cast(s_time/1000 as int),'yyyy-MM-dd HH:mm:ss'))FROM event_log_20200510WHERE en="e_l" or en="e_pv";
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值