在创建表时,是否可以在配置单元中同时使用两个字段终止符(如“,”和“.”)?

rpppsulh  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(310)

我和你有个档案 id 以及 year . 我的领域被 , 以及 . . 有没有可能我可以在我可以使用的字段结束的地方 , 以及 . ?

0vvn1miw

0vvn1miw1#

这可以使用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';

在上述正则表达式中,定义了三个正则表达式组。

(\\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

详情请参见:https://community.hortonworks.com/articles/58591/using-regular-expressions-to-extract-fields-for-hi.html

相关问题