使用Pig将数据添加到hcatalog表

时间:2015-06-03 05:04:01

标签: apache-pig hcatalog

我有一个带编码数据的JSON文件。我的目标是解码数据并将其保存到具有模式(食物,人,数量)的HCat表中。

myfile.json

{"messages":[{"body":"eyJmb29kIjoiTWFuZ28iLCAicGVyc29uIjoiQWxpY2UiLCAiYW1vdW50IjoxMX0="}]}
{"messages":[{"body":"eyJmb29kIjoiQXBwbGUiLCAicGVyc29uIjoiVG9tIiwgImFtb3VudCI6MjJ9"}]}
{"messages":[{"body":"eyJmb29kIjoiT3JhbmdlIiwgInBlcnNvbiI6IkpvaG4iLCAiYW1vdW50IjozM30="}]}

我的代码

STOCK_A = LOAD 'myfile.json' 
USING JsonLoader('messages:{(body:chararray)}');    
rowarr1 = FOREACH STOCK_A GENERATE FLATTEN(messages.(body)) as (body);
decodearr = FOREACH rowarr1 GENERATE Base64Decode(body) as (msg);
DESCRIBE decodearr;        
DUMP decodearr;

输出

decodearr: {msg: chararray}
({"food":"Mango", "person":"Alice", "amount":11})
({"food":"Apple", "person":"Tom", "amount":22})
({"food":"Orange", "person":"John", "amount":33})

如何使用模式拆分和保存它 {food:chararray,person:chararray,amount:int}

0 个答案:

没有答案