改变parquet表的array< struct< >>类型的列会导致配置单元中的错误

f8rj6qna  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(392)

我有一个类型字段

array<struct<id:string>>

在配置单元中创建的分区Parquet地板表中。当我更改此列的类型以在结构部分中添加字段时,在某个select中分解数组时会出错。详情如下:
create table语句

CREATE EXTERNAL TABLE `test_table`(
  `my_array` array<struct<id:string>>)
PARTITIONED BY ( 
  `ymd` int)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'

用数据创建分区

insert overwrite table test_table
PARTITION (ymd = 20170101)
select
   array(named_struct('id', 'id1')) as my_array

然后在数组的sr结构中添加一个新字段

ALTER TABLE test_table 
CHANGE COLUMN my_array my_array array<struct<id:string, amount:int>>

这将更改表的元数据。我的期望是,过去的数据仍然可读,“amount”的值为空。不幸的是我遇到了一个我不明白的错误。为了更好的说明,让我先创建一个新分区:

insert overwrite table test_table
PARTITION (ymd = 20170102)
select
array(named_struct('id', 'id2', 'amount',2)) as my_array

现在,做一个

select * from test_table

产生我期望的结果(从ui输出):

但是,当我想用横向视图分解阵列时,会出现一个错误:

select
    my_array
from
    test_table t
    lateral view explode (my_array) arry as a

此查询引发配置单元运行时错误。相关日志应为本段之后的日志。当选择“arry.a”而不是“my\u array”时,会出现非常类似的错误。令人惊讶的是,下面的查询运行得很好,得到了我所期望的结果:

select
    ymd,
    a.id,
    a.amount
from
    test_table t
    lateral view explode (my_array) arry as a


在我看来,这可能是一个错误。下面是运行上面的select时导致错误的一段日志。配置单元版本为1.1.0-cdh5.8.0:

Error: java.lang.RuntimeException: 
org.apache.hadoop.hive.ql.metadata.HiveException: 
Hive Runtime Error while processing row {"my_array":[{"id":"id1","amount":null}],"ymd":20170101} at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.map(ExecMapper.java:179) at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54) at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:453) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:343) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1693) at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) 
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row {"my_array":[{"id":"id1","amount":null}],"ymd":20170101} at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:507) at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.map(ExecMapper.java:170) ... 8 more 
Caused by: java.lang.UnsupportedOperationException: Cannot inspect java.util.ArrayList at org.apache.hadoop.hive.ql.io.parquet.serde.ArrayWritableObjectInspector.getStructFieldsDataAsList(ArrayWritableObjectInspector.java:172) at org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.serialize(LazySimpleSerDe.java:355) at org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.serialize(LazySimpleSerDe.java:319) at org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.serializeField(LazySimpleSerDe.java:258) at org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.doSerialize(LazySimpleSerDe.java:242) at org.apache.hadoop.hive.serde2.AbstractEncodingAwareSerDe.serialize(AbstractEncodingAwareSerDe.java:55) at org.apache.hadoop.hive.ql.exec.FileSinkOperator.processOp(FileSinkOperator.java:668) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.SelectOperator.processOp(SelectOperator.java:84) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.LateralViewJoinOperator.processOp(LateralViewJoinOperator.java:133) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.UDTFOperator.forwardUDTFOutput(UDTFOperator.java:125) at org.apache.hadoop.hive.ql.udf.generic.UDTFCollector.collect(UDTFCollector.java:45) at org.apache.hadoop.hive.ql.udf.generic.GenericUDTF.forward(GenericUDTF.java:107) at org.apache.hadoop.hive.ql.udf.generic.GenericUDTFExplode.process(GenericUDTFExplode.java:94) at org.apache.hadoop.hive.ql.exec.UDTFOperator.processOp(UDTFOperator.java:108) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.SelectOperator.processOp(SelectOperator.java:84) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.LateralViewForwardOperator.processOp(LateralViewForwardOperator.java:37) at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:815) at org.apache.hadoop.hive.ql.exec.TableScanOperator.processOp(TableScanOperator.java:95) at org.apache.hadoop.hive.ql.exec.MapOperator$MapOpCtx.forward(MapOperator.java:157) at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:497) ... 9 more
krcsximq

krcsximq1#

我们通过编写一个自定义serde来解决这个问题,每当在文件中找不到列时,它就为数据提供空值。

相关问题