正则表达式SerDe不支持serialize()方法错误 [英] Regex SerDe doesn't support the serialize() method error

查看:217
本文介绍了正则表达式SerDe不支持serialize()方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格结构如下.

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.

由于:java.lang.UnsupportedOperationException:正则表达式SerDe 不支持serialize()方法 在org.apache.hadoop.hive.serde2.RegexSerDe.serialize(RegexSerDe.java:289)

Caused by: java.lang.UnsupportedOperationException: Regex SerDe doesn't support the serialize() method at org.apache.hadoop.hive.serde2.RegexSerDe.serialize(RegexSerDe.java:289)

有什么想法吗?

推荐答案

您使用了错误的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 ,它可以使用

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()方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆