使用Hive的正则表达式匹配数据时为NULL

来源:互联网 发布:时间煮雨 知乎 编辑:程序博客网 时间:2024/05/17 08:21

今天要将Ngix用户访问日志导入到Hive表中,日志的格式是这样的:

120.221.0.66 - - [22/Aug/2017:03:46:04 +0800] "GET /xx/xx-162.patch HTTP/1.1" 304 0 "-" "Mozilla/5.0 Gecko/20100115 Firefox/3.6" "-",所以就使用了正则表达式的方式,来匹配每一个字段,在http://wpjam.qiniudn.com/tool/regexpal/里,明明全部匹配到了,但是导入到Hive表中的时候,数据就是为Null,

drop table if exists default.ansun_log_src ;
create table IF NOT EXISTS default.ansun_log_src (
remote_ip string,
remote_addr string,
remote_user string,
time_local string,
request string,
status string,
status2 string,
status3 string,
version string,
host string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
  "input.regex" = "([^ ]*) (-|[^ ]*) ([^\]]*) (\"[^\"]*\") (\"[^\]]*\") ([0-9]*) ([0-9]*) (\"-|[^ ]*\") (\"[^\"]*\") (\"-|[^ ]*\")"
)
stored as textfile ;


百度了很久,终于找到了答案,原因就在于在方括号中,正则表达式中的字符转义跟一般情况下的转义不一样。

参考:http://www.cnblogs.com/echomyecho/p/3340987.html 以及 http://blog.sina.com.cn/s/blog_6ff05a2c0100voxd.html


原创粉丝点击