如何在Impala中有效地从单个行创建多个行

时间:2019-07-11 08:39:56

标签: optimization impala

我的table1具有以下格式:

UT | temp_m1  | temp_m2  | temp_m3  | temp_m4  | air_m1  | air_m2  | air_m3  | air_m4  |    

我想用这种格式产生table2:

UT | location  |   temp  | air

table1的每一行将有4行。

实现此目标的简单方法是:

create table2 as
Select ut,'m1' as location, temp_m1 as temp, air_m1 as air 
from table1
union all 
Select ut,'m2' as location, temp_m2 as temp, air_m2 as air 
from table1
union all 
Select ut,'m3' as location, temp_m3 as temp, air_m3 as air 
from table1
union all 
Select ut,'m4' as location, temp_m4 as temp, air_m4 as air 
from table1;

但是看任务管理器,似乎我们必须读取同一张表4次,然后将结果联接起来。

应该只读一次然后在“目标”位置将其拆分会更容易,但是我找不到办法。

0 个答案:

没有答案