Pig默认的JsonLoader模式问题 [英] Pig default JsonLoader schema issue
本文介绍了Pig默认的JsonLoader模式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的数据需要使用Pig分析
数据
{
Name:BBQ Chicken,
Sizes:[
{Size:Large价格:14.99},
{尺寸:中等,价格:12.99}
],
浇头:[烧烤酱,鸡肉奶酪]
}
我可以定义名称
和大小
但我无法获得浇头
工作。
$ b
脚本
$ c $ data> LOAD'/user/hue/data/nested_json_pizza_sample_data.json'USING JsonLoader('Name:chararray,
Sizes:bag {tuple(Size:chararray,Price:float)},
浇头:元组(a:chararray)');
DUMP数据;
输出
<
(BBQ Chicken,{(Large,14.99) ,(中等,12.99)},)
(夏威夷,{(大,12.99),(中,10.99)},)
(Vegetable,{(Large,12.99), },)
(辣椒,{(大,12.99),(中等,10.99),(小,7.49)},)
(奶酪,{(大,10.99),(中等,9.99) ,(Small,5.49)},)
data:{名称:chararray,尺寸:{(Size:chararray,Price:float)},浇头:(a:chararray)}
解决方案
这里有两个选择:如果数组中的项数在未知中。 p>
浇头:{t:(i:chararray)}
或者如果元素的数量总是相同的。
浇头: (i:chararray,j:chararray,k:chararray)
会输出:
(BBQ Chicken,{(Large,14.9 9),(Medium,12.99)},)
I've the below data that need to be parsed using Pig
Data
{
"Name": "BBQ Chicken",
"Sizes": [
{ "Size": "Large", "Price": 14.99 },
{ "Size": "Medium", "Price": 12.99 }
],
"Toppings": [ "Barbecue Sauce", "Chicken", "Cheese" ]
}
I am able to define the schema for Name
and Sizes
but I couldn't get the Toppings
working. Looking for some help here.
Script
data = LOAD '/user/hue/data/nested_json_pizza_sample_data.json'
USING JsonLoader('Name:chararray,
Sizes:bag{tuple(Size:chararray, Price:float)},
Toppings:tuple(a:chararray)');
DUMP data;
Output
As you can see below, the Topping's data is not being parsed.
(BBQ Chicken,{(Large,14.99),(Medium,12.99)},)
(Hawaiian,{(Large,12.99),(Medium,10.99)},)
(Vegetable,{(Large,12.99),(Medium,10.99)},)
(Pepperoni,{(Large,12.99),(Medium,10.99),(Small,7.49)},)
(Cheese,{(Large,10.99),(Medium,9.99),(Small,5.49)},)
data: {Name: chararray,Sizes: {(Size: chararray,Price: float)},Toppings: (a: chararray)}
解决方案
You have two options here : if the number of items in the array in unknown.
Toppings:{t:(i:chararray)}
Or if the number of elements going to be same allways.
Toppings: (i: chararray, j: chararray, k: chararray)
will give you output :
(BBQ Chicken,{(Large,14.99),(Medium,12.99)},)
这篇关于Pig默认的JsonLoader模式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文