我有一个json和json的值
000000,{“000”:{“phonenumber”:null,“firstname”:“xyz”,“lastname”:“pqr”,“email”:email@xyz.com“,”alternatepickup“:true,”sendtextnotification“:false,”issendtextnotification“:false,”isalternatepickup“:true}}
我正试图用象鸟json加载程序在pig中加载这个json,但无法做到这一点。
我可以加载以下json
{“000”:{“phonenumber”:null,“firstname”:“xyz”,“lastname”:“pqr”,“email”:email@xyz.com“,”alternatepickup“:true,”sendtextnotification“:false,”issendtextnotification“:false,”isalternatepickup“:true}}
使用以下脚本-
REGISTER json-simple-1.1.1.jar;
REGISTER elephant-bird-pig-4.3.jar;
REGISTER elephant-bird-hadoop-compat-4.3.jar;
json_data = load 'ek.json' using com.twitter.elephantbird.pig.load.JsonLoader() AS (json_key: [(phoneNumber:chararray,firstName:chararray,lastName:chararray,email:chararray,alternatePickup:boolean,sendTextNotification:boolean,isSendTextNotification:boolean,isAlternatePickup:boolean)]);
dump json_data;
但是当我从json中包含值时
json_data = load 'ek.json' using com.twitter.elephantbird.pig.load.JsonLoader() AS (id:int,json_key: [(phoneNumber:chararray,firstName:chararray,lastName:chararray,email:chararray,alternatePickup:boolean,sendTextNotification:boolean,isSendTextNotification:boolean,isAlternatePickup:boolean)]);
它不工作!!提前感谢你的帮助。
2条答案
按热度按时间yhived7q1#
您可以使用内置的jsonstorage和jsonload()
在这个例子中,数据是在没有模式的情况下加载的;它假设在输入目录中有一个.pig\u模式(由jsonstorage生成)。
3zwjbxry2#
JsonLoader
只允许加载正确的json,而您的格式实际上是CSV
. 您可以通过增加复杂性来选择三个选项:调整您的输入格式,使id成为其中的一部分
将数据加载为csv(作为两个字段:id和json,然后使用自定义udf将json字段解析为元组)
编写自定义加载程序,允许您使用原始格式。