Hive分区表新增字段查询为空

在开发过程中,向hive分区表新增字段,发现查询新增字段的值为NULL

解决方法:对分区增加相应的字段
alter table student partition(pt = '2020-01-13') add columns(birthday string);

1.创建分区表,并插入数据

create table student(id int,name string) partitioned by (pt string);
insert into table student partition(pt = '2020-01-13') select 1,'lyn';
insert into table student partition(pt = '2019-01-14') select 2,'tom';
  1. 查看数据
hive> select * from student;
OK
2   tom 2019-01-14
1   lyn 2020-01-13
Time taken: 0.189 seconds, Fetched: 2 row(s)
  1. 增加字段
alter table student add columns(birthday string);
insert into table student partition(pt = '2020-01-13') select 1,'sarah','1990-01-01';
insert into table student partition(pt = '2020-01-14') select 2,'cici','1989-05-21';
insert into table student partition(pt = '2020-01-15') select 3,'land','1988-01-25';
  1. 查看数据
hive> select * from student;
OK
2   tom NULL    2019-01-14
1   lyn NULL    2020-01-13
1   sarah   NULL    2020-01-13
2   cici    1989-05-21  2020-01-14
3   land    1988-01-25  2020-01-15
Time taken: 0.097 seconds, Fetched: 5 row(s)
  1. 解决方法
-- 对于在增加字段前已经存在的分区,必须再执行
alter table student partition(pt = '2020-01-13') add columns(birthday string);

hive> select * from student;
OK
2   tom NULL    2019-01-14
1   lyn NULL    2020-01-13
1   sarah   1990-01-01  2020-01-13
2   cici    1989-05-21  2020-01-14
3   land    1988-01-25  2020-01-15
Time taken: 0.103 seconds, Fetched: 5 row(s)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容