hive分区表添加字段问题

在分区表里增加字段后,向分区表插入数据有两种情况:

1.分区在修改表结构前存在

2.分区在修改表结构前不存在

对于第二种情况,bug不存在

针对第一种情形,

执行alter table denglg add columns(c3 string);  查分区数据新增字段值为空,

需再执行alter table denglg partition(step='1') add columns(c3 string);【假设当前只有step='1'的分区】

这个bug可以workaround

具体测试如下,可以参考看看

1.新建分区表,插入两个分区的数据

  1. CREATE TABLE testtmp.denglg(c1 string, c2 string)PARTITIONED BY (step string);
    insert into table testtmp.denglg partition(step='1')select'1','2'fromdefault.dual;
    insert into table testtmp.denglg partition(step='2')select'11','22'fromdefault.dual;
    hive>select*from denglg where step='1';  
    OK                                                                 
    1          2         1                                                               
    hive>select*from denglg where step='2';
    OK
    11        22       2

2.新增字段c3 

  1. alter table denglg add columns(c3 string);

3.向三个分区插入数据

  1. insert into table testtmp.denglg partition(step='1') select '1','2','3' from default.dual;
    insert into table testtmp.denglg partition(step='2') select '11','22','33' from default.dual;
    insert into table testtmp.denglg partition(step='3') select '111','222','333' from default.dual;
    hive> select * from denglg where step='1';
    OK
    12    NULL    1
    12    NULL    1
    Time taken:0.122 seconds,Fetched:2 row(s)
    hive> select * from denglg where step='2';
    OK
    1122    NULL    2
    1122    NULL    2
    Time taken:0.075 seconds,Fetched:2 row(s)
    hive> select * from denglg where step='3';
    OK
    111 222 333 3
    Time taken:0.077 seconds,Fetched:1 row(s)

发现分区step=3不受影响

4.执行

  1. alter table denglg partition(step='1') add columns(c3 string);
    hive> select * from denglg where step='1';
    OK
    12    NULL    1
    1 2 3 1
    Time taken:0.728 seconds,Fetched:2 row(s)
    hive> select * from denglg where step='2';
    OK
    11 22    NULL    2
    11 22    NULL    2

     

 

 



posted on 2015-12-11 15:34 艺术家烦高 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/chitin1027/p/bcd9d024876b21b2c7d1fe7f5177fbc4.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值