hive复杂类型

avkwfej4  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(291)

如何使用配置单元复杂类型处理一对多关系?例如,给定两个表:

artist: artist_id, first_name, last_name 
song:  song_id, song_name, song_date, artist_id

如何编写hiveql或sql以将歌曲集合包含到独特的艺术家中,即。
例如

112, drew, jackson, {10: [hill, 1992], 13: [away, 2011], .... }
113, maria,mcmillan, {25: [denial, 2000], 26: [fly, 1990], .... }
0dxa2lsx

0dxa2lsx1#

select      a.artist_id, a.first_name, a.last_name 
           ,s.songs

from                    artist  as a

            left join  (select      artist_id
                                   ,concat('{',concat_ws(',',collect_list(concat(cast(song_id as string),':[',song_name,',',cast(song_date as string),']'))),'}') as songs

                        from        song    as s

                        group by    artist_id
                        ) s

            on          s.artist_id =
                        a.artist_id
;

相关问题