impala分區表用insert into...select插入數據

1,兩張表,ta,tb

create table ta(id int,name string) partition(year int,month int);

create table tb(id int,name string) partition(year int,month int);

 

2,insert ta select tb

一,插入ta的靜態分區

insert into ta partition(year=2019,month=4) select id,name from tb [where year=2019 and month=3];

此時不能用select * from tb;  代替 select id,name from tb; 因爲分區字段year和month 在ta中已經有值,在tb中查詢出其他字段即可,select * 包含分區字段,而此時不需要分區字段的值

如果兩個表有大量字段怎麼辦?還不是都寫出來。。。

二,插入ta的動態分區

insert into ta partition(year,month) select * from tb [where year=2019 and month=3];

此時的分區字段在ta中沒有值,會被tb中的分區字段值所覆蓋,所有可以這麼寫

三,部分動態,部分靜態

insert into ta partition(year=2019,month) select id,name,month from tb [where year=2019 and month=3];

需要把動態分區列出,同理,因爲動態分區month沒有值,需要被覆蓋

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章