Pig default JsonLoader schema issue

风流意气都作罢 提交于 2020-01-11 11:29:13

问题


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)}

回答1:


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)},)


来源:https://stackoverflow.com/questions/21076583/pig-default-jsonloader-schema-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!