2016-10-06 53 views
1

電影表豬腳本合併後的行加入和group by

id movie genre 
1 ABC A|B|C 
2 DEF D|A|F 

有它們由|分隔符分隔多個流派。

評分表:

user_id movie_id rating 
1  1   3.5 
1  2   4.5 

結果:

我想要的結果作爲user_id +所有類型

user_id genres 
1  (A|B|C|D|A|F) 

代碼:

genre_data = join movie by id, ratings by movie_id; 
genre_data = group genre_data by (user_id); 
user1_data = foreach genre_data generate ratings::user_id, movie::genre; 

回答

1

您可以通過實現它:

genre_data = join movie by id, ratings by movie_id; 
genre_data = group genre_data by user_id; 

user_data = foreach genre_data { 
    genres = foreach genre_data generate movie::genre as genres; 
    generate group as user_id, BagToString(genres, '|'); 
}; 
+0

thanku..this的作品! –