【问题标题】:Regex SerDe doesn't support the serialize() method errorRegex SerDe 不支持 serialize() 方法错误
【发布时间】:2018-12-12 13:55:39
【问题描述】:

我有一个如下表结构。

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.hadoop.hive.serde2.RegexSerDe.serialize(RegexSerDe.java:289)

知道出了什么问题吗?

【问题讨论】:

    标签: regex hadoop hive hiveql regexserde


    【解决方案1】:

    您使用了错误的 SerDe 类。 org.apache.hadoop.hive.serde2.RegexSerDe 不支持序列化。看看source code - 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.hadoop.hive.contrib.serde2.RegexSerDe,它可以使用format 字符串序列化行对象。序列化格式应在SERDEPROPERTIES 中指定。查看source code了解更多详情。

    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';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 2021-06-17
      • 2020-05-15
      • 2021-12-23
      相关资源
      最近更新 更多