Hive 如何在配置单元中将列转换为行

Hive 如何在配置单元中将列转换为行,hive,Hive,我在蜂房里有一张像这样的桌子 cust_1,month_1, f1,f2,f3 cust_1,month_2, f2,f3,f4 cust_2,month_1, f1,f5,f4 我想将其转换为以下格式 cust_1,month_1, f1 cust_1,month_1, f2 cust_1,month_1, f3 在蜂箱里这怎么可能 您可以使用以下sql: select col1, col2, value from orig_table lateral view

我在蜂房里有一张像这样的桌子

cust_1,month_1, f1,f2,f3 
cust_1,month_2, f2,f3,f4   
cust_2,month_1, f1,f5,f4
我想将其转换为以下格式

cust_1,month_1, f1
cust_1,month_1, f2   
cust_1,month_1, f3

在蜂箱里这怎么可能

您可以使用以下sql:

select col1, col2, value 
     from orig_table lateral view explode(array(col3,col4,col5)) orig_table_alias as value;

这是相当基本的东西。配置单元没有pivot/unpivot,因此只需
select cust,month,f1 union all select cust,month,f2…
@Andrew
union all
来透视配置单元中的数据效率很低。如果要从宽变长,可以创建键值对并分解。在下面的回答中概述了它。可能重复