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

8 篇文章 0 订阅

hive在修改表的字段类型时使用语法:

ALTER TABLE table_name PARTITION partition_spec] 
CHANGE COLUMN] col_old_name col_new_name column_type COMMENT col_comment] 
FIRST|AFTER column_name] CASCADE|RESTRICT];

--新增字段

alter table t66_cust_event add columns (oppp_cust_id string);

--修改类型及增加注释

alter table t66_cust_event change column oppp_cust_id oppp_cust_id_2 string comment 'test';

--移动字段顺序

alter table t66_cust_event change column oppp_cust_id oppp_cust_id_2 string comment 'test'
after col1;

 PS:移动操作须针对已存在的字段,在字段新增的时候,不能直接和移动操作一起

        此操作在修改已有数据的表时,会报错,因为修改元数据,并未修改原始数据


官方解释:

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.

列更改命令将只修改Hive的元数据,而不修改数据。用户应该确保表/分区的实际数据布局符合元数据定义。


--在删除一个或多个字段之后,原始数据的原始字段的值不会随之丢失(要区分数据与元数据

// 删除字段(使用新schema替换原有的)
ALTER TABLE t66_cust_event REPLACE COLUMNS(id BIGINT, name STRING ......);

 

^  - ^ ……

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值