用 Pig 解析“复杂"的 JSON [英] Parsing 'Complex' JSON with Pig
本文介绍了用 Pig 解析“复杂"的 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一些中等复杂的 JSON
Say I have some moderately complex JSON like
{
"revenue": 100,
"products":[
{"name": "Apple", "price": 50},
{"name": "Banana", "price": 50}
]
}
显然这有点做作,但是使用 JsonLoader 将其映射到 pig 的最佳方法是什么.
Obviously this this a bit contrived, but what's the best way to map this to pig using JsonLoader.
我试过了
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:[(name:chararray,price:int)]');
或
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:[{(name:chararray,price:int)]}');
然而,当我 DUMP A
时,我得到 (100,)
两个.
However, when I DUMP A
, I get (100,)
for both.
我也试过
a = LOAD '/json/complex.json'
USING JsonLoader('revenue:int,products:[{name:chararray,price:int}]');
哪个错误出现 ERROR 1200: <第 1 行,第 28 列>不匹配的输入 'chararray' 需要 LEFT_PAREN
.
解析它以备将来使用的最佳方法是什么?
What's the best way to parse this for future use?
谢谢
推荐答案
为了后人,
a = LOAD 'test.json' USING
JsonLoader('revenue:int,products:{(name:chararray,price:int)}');
这篇关于用 Pig 解析“复杂"的 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文