我有一个包含编码数据的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}的模式来分割和保存这个呢
暂无答案!
目前还没有任何答案,快来回答吧!