2016-04-01 32 views
0

我正嘗試使用JsonLoader從JSON文件中使用Pig時輸入數據集的模式。在PIG中定義JsonLoader中的模式

數據的格式爲:

{ 
    'cat_a':'some_text', 
    'cat_b':{(attribute_name):(attribute_value)} 
} 

我試圖描述的模式爲:

LOAD 'filename' USING JsonLoader('cat_a:chararray, cat_b:(attribute_name:chararray,attribute_value:int)'); 

我覺得我所描述的模式不正確的cat_b

有人可以幫忙嗎? 在此先感謝。

回答

0

如果JSON的格式爲

{"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}]} 

test.json

運行下面的命令上面JSON

a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)}'); 

dump a; 

你將有輸出

(Tacos,{(Beef),(Lettuce),(Cheese)},) 

,如果你的JSON是像下面的格式

{"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}],"inventor":{"name":"Alex","age":25}} 

a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)},inventor: (name:chararray, age:int)'); 


dump a; 

輸出將

(Tacos,{(Beef),(Lettuce),(Cheese)},(Alex,25)) 
+0

這是否回答你的問題......? –