2016-12-20 10 views
2

ハイブ複合型を使用して1対多リレーションシップを処理する方法は?1対多リレーションシップを処理するハイブ複合型

ユニークなアーティストに曲のコレクションを含めること、すなわち

例えばをhiveqlまたはSQLを記述する方法

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

:例えば、2つのテーブルを与えられました

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

明確ではありません。あなたはテーブル定義をお探しですか?あるフォーマットから別のフォーマットにデータを変換するクエリ? –

+0

はい、2つのテーブルのデータを例に変換するクエリ – DevEx

答えて

2
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 
; 
関連する問題