2017-09-26 9 views
0

jsonファイルをハイブで読み込もうとしています。下はサンプルのjsonファイルです。jsonファイルをハイブで解析する

{"Result":[ 
{"Col1":"Key1","Col2":"[email protected]","Col3":"7"}, 
{"Col1":"Key2","Col2":"[email protected]","Col3":"7"}, 
{"Col1":"Key3","Col2":"[email protected]","Col3":"7"}, 
{"Col1":"Key4","Col2":"[email protected]","Col3":"7"} 
]} 

私はハイブで以下の文を作成しようとしました。

create table if not exists sample_json (A Array<struct<"Col1":String,"Col2":string,"Col3":string>>) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' LOCATION '/a/b/c' 

は、私は、配列を爆発しようとしていtable.Iから各列のデータを取得できないのですが、それは誰もがそれと間違っているものを提案してください.Canのみ第一のレコードを返しますか?

答えて

0

結果

SELECT 
     t.col1 
     ,t.col2 
     ,t.col3 
    FROM 
     testJson LATERAL VIEW explode (result) r AS t LIMIT 100 

CREATE EXTERNAL TABLE testJson (
     Result ARRAY <struct<Col1:String , 
          Col2 : string , 
          Col3 : string > >) 
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' 
LOCATION 's3n://temp_db.db/testjsonstring'; 

クエリを作成します

Col1 Col2   Col3 
Key1 [email protected] 7 
Key2 [email protected] 7 
Key3 [email protected] 7 
Key4 [email protected] 7 
+1

ありがとう@rbyndoorこれは、別々の読み込みinpathステートメントを書き込んだ後に動作しました。 – user1734980