Hive alter table column 在具有 struct column 时失败

Hive alter table column fails when it has struct column

我已经在外部创建了配置单元 table。

CREATE EXTERNAL TABLE test_db.test_table (
   `testfield` string,
   `teststruct` struct<teststructfield:string>
   )
 ROW FORMAT SERDE                                   
   'org.apache.hive.hcatalog.data.JsonSerDe'        
 STORED AS INPUTFORMAT                              
   'org.apache.hadoop.mapred.TextInputFormat'       
 OUTPUTFORMAT                                       
   'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
 LOCATION                                           
   'hdfs://some/path';


hive> describe test_table;

+-------------+---------------------------------+--------------------+
|  col_name   |            data_type            |      comment       |
+-------------+---------------------------------+--------------------+
| testfield   | string                          | from deserializer  |
| teststruct  | struct<teststructfield:string>  | from deserializer  |
+-------------+---------------------------------+--------------------+

我想更改 table 列。
但是当 table 有结构列 (teststruct) 时, < 小于符号时发生错误。

ALTER TABLE test_db.test_table CHANGE COLUMN testfield testfield2 string;

INFO  : Semantic Analysis Completed (retrial = false)
INFO  : Returning Hive schema: Schema(fieldSchemas:null, properties:null)
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Starting task [Stage-0:DDL] in serial mode
ERROR : FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Error: type expected at the position 7 of 'string:<derived from deserializer>' but '<' is found.

没有具有 < 的结构列,它成功了。这个问题我该怎么办?

如果没有其他帮助,作为解决方法,您可以 drop/create table 并恢复分区。 table 是外部的,删除不会影响数据。

(1) 掉落 table

DROP TABLE test_db.test_table;

(2) 使用所需的列名

创建 table
CREATE EXTERNAL TABLE test_db.test_table (
   testfield2 string,
   teststruct struct<teststructfield:string>
   )
   PARTITIONED BY (....)
 ROW FORMAT SERDE                                   
   'org.apache.hive.hcatalog.data.JsonSerDe'        
 LOCATION                                           
   'hdfs://some/path';

(3) 恢复分区

MSCK REPAIR TABLE test_db.test_table;

或者如果您是 运行 EMR 上的 Hive:

ALTER TABLE test_db.test_table RECOVER PARTITIONS;