Can I use 2 fields terminators(like ',' and '.') at a time in hive while creating table?

被刻印的时光 ゝ 提交于 2019-12-20 03:56:10

问题


I have a file with id and year. My fields are separated by , and .. Is there any chance I can in the place of fields terminated by can I use , and .?


回答1:


This is possible using RegexSerDe.

hive> CREATE EXTERNAL TABLE citiesr1 (id int, city_org string, ppl float) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' 
WITH SERDEPROPERTIES ('input.regex'='^(\\d+)\\.(\\S+),(\\d++.\\d++)\\t.*')
LOCATION '/user/it1/hive/serde/regex';

In the regex above three regex groups are defined.

(\\d+) leading digits is the int id column
dot . is a separator
(\\S+) - string without spaces is the city_org string column
comma , is a separator
(\\d++.\\d++) - float column
\\t - tab separator

See details here: https://community.hortonworks.com/articles/58591/using-regular-expressions-to-extract-fields-for-hi.html



来源:https://stackoverflow.com/questions/47937735/can-i-use-2-fields-terminatorslike-and-at-a-time-in-hive-while-creatin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!