在分區表里增加字段后,向分區表插入數據有兩種情況:
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.新建分區表,插入兩個分區的數據
-
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
-
alter table denglg add columns(c3 string);
3.向三個分區插入數據
-
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.執行
-
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