hive 添加,修改,删除字段的坑

6 篇文章 0 订阅

 

alter table table_name add  columns(location_id string) ;

alter table table_name change column complete_status complete_status string;

使用alter table语句更新变结构时,由于默认更行现有表结构,对历史分区表元数据无改动,导致原有分区变数据,新字段为null,

重新更新历史分区表也无动于衷,没有效果。

hive 1.1.0以前办法,

alter table table_name  partition(p='20190101') add  columns(location_id string) ;

alter table table_name partition(p='20190101') change column complete_status complete_status string;

通过添加partition一个一个分区修改 ,

hive 1.1.0后可以使用cascoda,在alter table语句后添加cascoda关键字执行,一劳永逸。

注意:CASCADE命令更改表更改列将更改表元数据的列,并将相同的更改级联到所有分区元数据

alter table table_name add  columns(location_id string) cascoda|restrict;

alter table table_name change column complete_status complete_status string cascoda|restrict;

官方解释:

The CASCADE|RESTRICT clause is available in Hive 1.1.0. ALTER TABLE CHANGE COLUMN with CASCADE command changes the columns of a table’s metadata, and cascades the same change to all the partition metadata. RESTRICT is the default, limiting column change only to table metadata.

ALTER TABLE CHANGE COLUMN CASCADE clause will override the table partition’s column metadata regardless of the table or partition’s protection mode. Use with discretion.

The column change command will only modify Hive’s metadata, and will not modify data. Users should make sure the actual data layout of the table/partition conforms with the metadata definition.

 

 

  • 2
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值