将多列合并为配置单元中的单列
combining multiple columns in to single columns in hive
我有一个 table 如下所示。
Id v1 v2 v3
A 01 03 23
B 11 21 05
C 02 10 24
D 22 14 23
此处第一列有 id,它与三列相关。所以我必须将这三列合并为一个具有相关 ID 的列。
例如
id value
A 01
A 03
A 23
B 11
B 21
B 05
. ..
. ..
所以我必须在蜂巢中这样做所以请告诉我。
select id, v1
from table
union all
select id, v2
from table
union all
select id, v3
from table
insert into table result_table select Id, v1 as value from orig_table;
insert into table result_table select Id, v2 as value from orig_table;
insert into table result_table select Id, v3 as value from orig_table;
select Id,value from result_table;
或
select Id, value
from orig_table LATERAL VIEW explode(array(v1,v2,v3)) orig_table_alias AS value;
我有一个 table 如下所示。
Id v1 v2 v3
A 01 03 23
B 11 21 05
C 02 10 24
D 22 14 23
此处第一列有 id,它与三列相关。所以我必须将这三列合并为一个具有相关 ID 的列。
例如
id value
A 01
A 03
A 23
B 11
B 21
B 05
. ..
. ..
所以我必须在蜂巢中这样做所以请告诉我。
select id, v1
from table
union all
select id, v2
from table
union all
select id, v3
from table
insert into table result_table select Id, v1 as value from orig_table;
insert into table result_table select Id, v2 as value from orig_table;
insert into table result_table select Id, v3 as value from orig_table;
select Id,value from result_table;
或
select Id, value
from orig_table LATERAL VIEW explode(array(v1,v2,v3)) orig_table_alias AS value;