正则表达式访问登录蜂巢serde [英] regex for access log in hive serde

查看:111
本文介绍了正则表达式访问登录蜂巢serde的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从访问日志中提取出(ip,requestUrl,timeStamp)以加载到配置单元数据库。来自访问日志的一行如下。



  
66.249.68.6 - - [14 / Jan / 2012/06:25:03 -0800]GET /example.com HTTP / 1.1200 708 - Mozilla / 5.0(compatible; Googlebot / 2.1; + http://www.google.com/bot.html )



我尝试了以下几种正则表达式,没有任何成功。 (所加载的表格全部为空值,表示正则表达式与输入不匹配)。

  
CREATE TABLE access_log(
remote_ip STRING,
request_date STRING,
方法STRING,
请求STRING,
协议STRING

行格式SERDE'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES(
input.regex=([^] )。[([^]] +)] \([^] )([^] )([^ \] )\*,
output.format。字符串=%1 $ s%2 $ s%3 $ s%4 $ s%5 $ s

作为TEXTFILE存储;



我对正则表达式不太了解。有人可以帮我解决这个问题吗?

解决方案

我使用 rubular 来测试我的正则表达式
您也可以使用这个表达式

 ([^] *)([^] *)([^] *)(?: -  | \ [([^ \]] *)\])([^ \] * | \[^ \] * \)( -  | [0-9] *) 

您将获得以下输出:

  1。 66.249.68.6 
2. -
3. -
4.14 / Jan / 2012:06:25:03 -0800
5.GET /example.com HTTP / 1.1
6. 200


I want to extract out (ip, requestUrl, timeStamp) from the access logs to load to hive database. One line from access log is as follows.


66.249.68.6 - - [14/Jan/2012:06:25:03 -0800] "GET /example.com HTTP/1.1" 200 708 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

I tried with following and several variations of regex without any success. (The loaded table is with all NULL values indicating the regex doesn't match the input).


CREATE TABLE access_log (
  remote_ip STRING,
  request_date STRING,
  method STRING,
  request STRING,
  protocol STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES  (
"input.regex" = "([^ ]) . . [([^]]+)] \"([^ ]) ([^ ]) ([^ \"])\" *",
"output.format.string" = "%1$s %2$s %3$s %4$s %5$s"
)
STORED AS TEXTFILE;

I am not very experienced with regex. Can anybody help me with this?

解决方案

I use rubular to test my regex. You can also use this expression

([^ ]*) ([^ ]*) ([^ ]*) (?:-|\[([^\]]*)\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*)

You get the following output

1.  66.249.68.6
2.  -
3.  -
4.  14/Jan/2012:06:25:03 -0800
5.  "GET /example.com HTTP/1.1"
6.  200

这篇关于正则表达式访问登录蜂巢serde的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆