这篇文章介绍如何用hive来分析一个网站访问日志文件。这里假定你已经安装好了一个跟hadoop集群(pseudo mode亦可)协作的hive,如果还没有,看 这里 建表 hive> create table coupon11_log (day string, time string, usernameid string, ip string, url string) row format serde ‘org.apache.hadoop.hive.contrib.serde2.RegexSerDe’ with serdeproperties( “input.regex” = “([^\\s]+)\\s+([^\\s]+)\\s+[^\\s]+\\s+[^\\s]+\\s+[^\\s]+\\s+[^\\s]+\\s+\-\\s+userNameId\-([^\\s]+)\\s+from\\s+IP\-([^\\s]+)\\s+invoked\\s+URL\-([^\\s]+).*” ); — 这个正则表达式就是访问日志的正则,一共5个括号,对应表里的5列 从HDFS载入数据文件到表中 hive> load data inpath ‘/user/coupon11log’ overwrite into table coupon11_log; –这里其实只会复制文件,不会解析它,所以这一步很快 select * from coupon11_log limit 10; — 小看一下装载进来的数据 试一个简单的统计查询 hive> select url, count(*) as …
[Hadoop] 例示Hive的使用 Read More »