我有如下配置的 hive 表:
create table alpha001(id int, name string) clustered by (id) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')
现在,我想删除其中一列,说“名称”。我尝试了以下方法:
ALTER TABLE alpha001 REPLACE COLUMNS (id int);
结果如下
Exception thrown: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Replace columns is not supported for table default.alpha001. SerDe may be incompatible.
和以下
ALTER TABLE alpha001 DROP name;
Exception thrown : FAILED: ParseException line 1:26 mismatched input 'name' expecting PARTITION near 'DROP' in drop partition statement
最佳答案
不幸的是,你不能!从现有表中删除列的唯一方法是使用REPLACE COLUMNS
关键字。但这仅适用于具有本地SerDe(DynamicSerDe,MetadataTypedColumnsetSerDe,LazySimpleSerDe和ColumnarSerDe)的表。
最好的选择是重新创建架构。遵循步骤。
alter table alpha001 set tblproperties('EXTERNAL'='TRUE');
进行快速采样。
create table alpha001(id int, name string) clustered by (id) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true');
--assuming your table is not EXTERNAL already
alter table alpha001 set tblproperties('EXTERNAL'='TRUE');
insert into alpha001 values(1,"A");
select * from alpha001;
drop table alpha001;
create table alpha001(id int) clustered by (id) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true');
select * from alpha001;
希望对您有所帮助!
关于hive - 配置为ORC的Hive表的删除列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32068903/