First, the question
How Hive will
1 represents the user, a represents the user's attributes, and the 0/1/0 represents the characteristic value
1 A1 0
1 A2 1
1 A3 0
Into:
1 a1,0 a2,1 a3,0
Second, the data
Split with \ t
[Jiangzl@master tmp]$ Cat Jiangzl.txt
1 A1 0
1 A2 1
1 A3 0
Third, the answer
1. Build a table
drop table iangzl_test;
CREATE TABLE Jiangzl_test (
col1 int,
Col2 string,
col3 int
)
Row format delimited
Fields terminated by ' \ t '
stored as textfile;
Load data local inpath '/home/jiangzl/work/tmp/jiangzl.txt ' into table default.jiangzl_test;
2. Handling
Select col1, Data[0], data[1], data[2]
From (
Select col1, Collect_set (Concat_ws (', ', col2, cast (col3 as String)) data
From Jiangzl_test
GROUP BY col1
) T;
Iv. About Us
This article author: one of the pioneer members of the data Jiang Zhong Lian
QQ Group: 248087140
Motto:
you're in the field you're good at,
and with a group of small white change
others will respect you from the heart.
--Click to join US
Marking display based on the user's image "column to row" feature