Hive分區表新增字段,查詢為Null


1.問題

在開發過程中,向hive分區表新增字段,發現查詢新增字段的值為NULL

2.問題復現

1.創建分區表,並插入數據

create table student(id int,name string) partitioned by (dt string);
insert into table student partition(dt = '2019-11-13') select 1,'zhangsan';
insert into table student partition(dt = '2019-11-14') select 2,'lisi';
select  * from student where dt = '2019-11-13';

select  * from student where dt = '2019-11-14';

2.增加字段,插入數據

alter table student add columns(sex string);
insert into table student partition(dt = '2019-11-13') select 1,'zhangsan','male';
insert into table student partition(dt = '2019-11-14') select 2,'lisi','female';
insert into table student partition(dt = '2019-11-15') select 3,'wangwu','female';

3.驗證

select  * from student where dt = '2019-11-13';

select  * from student where dt = '2019-11-14';

但是 impala查詢正常

select  * from student where dt = '2019-11-15';

4.結論

  1. 分區在增加字段前存在,會出現查詢新增字段值為NULL的情況
  2. 分區在增加字段前不存在,正常

3.解決方法

對於在增加字段前已經存在的分區,必須再執行

alter table student paritition(dt = '2019-11-14') add columns(sex string);

select  * from student where dt = '2019-11-14';


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM