我有一个如下的表结构。
CREATE TABLE db.TEST(
f1 string,
f2 string,
f3 string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
'input.regex'='(.{2})(.{3})(.{4})' )
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://nameservice1/location/TEST';
我试着在下表中插入一条记录。
insert overwrite table db.TEST2
select '12' as a , '123' as b , '1234' as c ;
在尝试将数据插入表时,遇到以下错误。
由java.lang.UnsupportedOperationException引起:Regex SerDe不支持serialize((方法网址:org.apache.hadop.hive.serde2.RegexSerDe.serialize(RegexSerDe.java:289(
知道出了什么问题吗?
您使用了错误的SerDe类org.apache.hadop.hive.serde2.RegexSerDe不支持序列化。查看源代码-serialize方法什么也不做,只抛出UnsupportedOperationException
异常:
public Writable serialize(Object obj, ObjectInspector objInspector)
throws SerDeException {
throw new UnsupportedOperationException(
"Regex SerDe doesn't support the serialize() method");
}
解决方案是
要使用另一个SerDe类:org.apache.hadop.hive.contrib.serde2.RegexSerDe,它可以使用格式字符串序列化行对象。应在SERDEPROPERTIES
中指定序列化格式。查看源代码以了解更多详细信息。
SerDe属性示例:
WITH SERDEPROPERTIES ( 'input.regex' = '(.{2})(.{3})(.{4})','output.format.string' = '%1$2s%2$3s%3$4s')
对于您的桌子,它将是这样的:
CREATE TABLE db.TEST(
f1 string,
f2 string,
f3 string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
'input.regex'='(.{2})(.{3})(.{4})',
'output.format.string' = '%1$2s%2$3s%3$4s' )
LOCATION
'hdfs://nameservice1/location/TEST';