我尝试使用JsonLoader从JSON文件中使用Pig时输入数据集的架构。
数据格式为:
{
'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
描述的模式不正确。有人可以帮忙吗?
提前致谢。
最佳答案
如果您的json是格式
{"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}]}
将上面的json存储在
test.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))
关于json - 在PIG的JsonLoader中定义架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347051/