如何使用多精度方法在配置单元中插入数据,并且在列之间未指定定界符。
以下是我的数据:
25380 20130101 2.514 -135.69 58.43 8.3 1.1 4.7 4.9 5.6 0.01 C 1.0 -0.1 0.4 97.3 36.0 69.4 -99.000 -99.000 -99.000 -99.000 -99.000 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0
25380 20130102 2.514 -135.69 58.43 3.0 -0.3 1.4 1.2 0.0 0.35 C 1.3 -1.0 -0.1 100.0 89.5 98.2 -99.000 -99.000 -99.000 -99.000 -99.000 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0
我只想在配置单元表中插入前7列,并且我有一个txt文件来存储上述数据。
创建表脚本:
CREATE TABLE hotcold (a int,b int,c float,d float,e float,f float,g float,h string,i string,j string,k string,l string,m string,n string,o string,p string,q string,
r string,s string,t string,u string,v string,w string,x string,y string,z string,aa string,bb string,cc string,dd string,ee string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES ('input.regex'='\\s+');
我的数据插入脚本如下:
LOAD DATA LOCAL INPATH '/home/cloudera/WeatherData.txt' into table hotcold;
下面是我的选择语句和错误:
select * from hotcold;
错误:
Failed with exception java.io.IOException:org.apache.hadoop.hive.serde2.SerDeException: Number of matching groups doesn't match the number of columns
答案 0 :(得分:1)
每列在正则表达式中应具有对应的捕获组()
。
在下面的示例中,字符串^(\\d+)
开头的第一组对应于正整数
\\s+
-一个或多个空格分隔符,
第二个捕获组对应于正整数(\\d+)
,
再次\\s+
-一个或多个空格分隔符,
第三捕获组-([+-]?[0-9.]+)
-浮点数,不是很严格的格式,允许+号以及didits和点的任意组合
和.*
最后允许未捕获的字符串末尾的任何字符,将所有其他列添加到正则表达式,我的示例包含三列(三个捕获组)的正则表达式:
WITH SERDEPROPERTIES ('input.regex'='^(\\d+)\\s+(\\d+)\\s+([+-]?[0-9.]+).*')
详细阅读:Using Regular Expressions to Extract Fields for Hive Tables