Pig 默认 JsonLoader 架构问题 [英] Pig default JsonLoader schema issue
本文介绍了Pig 默认 JsonLoader 架构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下需要使用 Pig 解析的数据
I've the below data that need to be parsed using Pig
数据
{
"Name": "BBQ Chicken",
"Sizes": [
{ "Size": "Large", "Price": 14.99 },
{ "Size": "Medium", "Price": 12.99 }
],
"Toppings": [ "Barbecue Sauce", "Chicken", "Cheese" ]
}
我能够为 Name
和 Sizes
定义架构,但我无法让 Toppings
工作.在此处寻求帮助.
I am able to define the schema for Name
and Sizes
but I couldn't get the Toppings
working. Looking for some help here.
脚本
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;
输出
如下所示,Topping 的数据没有被解析.
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)
会给你输出:
(BBQ Chicken,{(Large,14.99),(Medium,12.99)},)
这篇关于Pig 默认 JsonLoader 架构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文