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

     

 

 




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM