Aravind Yarram
Aravind Yarram

Reputation: 80176

Pig default JsonLoader schema issue

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

Upvotes: 1

Views: 2514

Answers (1)

vishnu viswanath
vishnu viswanath

Reputation: 3854

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

Upvotes: 2

Related Questions