gpt4 book ai didi

hive - 删除存储为 orc 的 Hive 表列

转载 作者:行者123 更新时间:2023-12-01 18:06:43 25 4
gpt4 key购买 nike

我创建的配置单元表如下:

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 关键字。但这仅适用于具有 native SerDe(DynamicSerDe、MetadataTypedColumnsetSerDe、LazySimpleSerDe 和 ColumnarSerDe)的表。

最好的选择是重新创建架构。按照步骤操作。

  1. 检查表是否是外部的。如果不是,请使用以下语句将其设为外部。

    alter table alpha001 set tblproperties('EXTERNAL'='TRUE');
  2. 删除表格。由于该表是外部表,因此您可以删除它而无需删除实际表。

  3. 使用新架构重新创建表。您应该能够使用新架构访问该表。

遵循快速示例。

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;
OK
1 A
drop table alpha001;

create table alpha001(id int) clustered by (id) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true');

select * from alpha001;
OK
1
Time tak

希望有帮助!

关于hive - 删除存储为 orc 的 Hive 表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32068903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com