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

今天要将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 ;

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

欢迎大家扫描下面二维码,或者搜索公众号:SimpleJava ,会经常分享Java,大数据等学习视频!

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

猜你喜欢

转载自blog.csdn.net/fengye1992/article/details/77929839
今日推荐