在创建表时,我可以在配置单元中一次使用2个字段终止符(如“,”和“。”)吗?

问题描述 投票:1回答:1

我有一个idyear的文件。我的田地被,.隔开。有没有机会我可以在终止的地方使用,.

hadoop hive hiveql hadoop2 hive-serde
1个回答
1
投票

使用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

© www.soinside.com 2019 - 2024. All rights reserved.