HHH
HHH

Reputation: 6465

how to convert columns into rows in HIVE

I have a table in HIVE which looks like this

cust_1,month_1, f1,f2,f3 
cust_1,month_2, f2,f3,f4   
cust_2,month_1, f1,f5,f4

I would like to convert it in the following format

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

....

How that is possible in HIVE?

Upvotes: 1

Views: 16637

Answers (1)

aaronshan
aaronshan

Reputation: 392

you can use this sql:

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

Upvotes: 3

Related Questions