问题描述
我的表格结构如下.
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';
我试图将记录插入到表中,如下所示.
I tried to insert a record into the table as below.
insert overwrite table db.TEST2
select '12' as a , '123' as b , '1234' as c ;
在尝试向表中插入数据时,遇到以下错误.
While trying to insert data into the table, facing the below error.
有什么想法吗?
推荐答案
您使用了错误的SerDe类. org .apache.hadoop.hive.serde2.RegexSerDe 不支持序列化.查看源代码-序列化方法不执行任何操作,但会引发UnsupportedOperationException
异常:
You are using wrong SerDe class. org.apache.hadoop.hive.serde2.RegexSerDe does not support serialization. Look at the source code - serialize method does nothing but throws UnsupportedOperationException
exception:
public Writable serialize(Object obj, ObjectInspector objInspector)
throws SerDeException {
throw new UnsupportedOperationException(
"Regex SerDe doesn't support the serialize() method");
}
解决方案是
使用另一个SerDe类: org .apache.hadoop.hive.contrib.serde2.RegexSerDe ,它可以使用格式字符串.序列化格式应在SERDEPROPERTIES
中指定.查看源代码以获取更多详细信息.
to use another SerDe class:org.apache.hadoop.hive.contrib.serde2.RegexSerDe, it can serialize the row object using a format string. Serialize format should be specified in the SERDEPROPERTIES
. Look at the source code for more details.
SerDe属性的示例:
Example of SerDe properties:
WITH SERDEPROPERTIES ( 'input.regex' = '(.{2})(.{3})(.{4})','output.format.string' = '%1$2s%2$3s%3$4s')
对于您的桌子,它是这样的:
For your table it will be like this:
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';
这篇关于正则表达式SerDe不支持serialize()方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!