Support Questions
Find answers, ask questions, and share your expertise

PIG Nested Json Query

PIG Nested Json Query

Explorer

sample-complex.txtHi All,

I am running PIG query as mentioned below

grunt> a = LOAD '/user/maria_dev/Sample_Complex.txt' USING JsonLoader ('recipe:chararray,ingredients:{(name:chararray)},inventor:(name:chararray,age:int)');

grunt> b = FOREACH a GENERATE recipe;

grunt> DUMP b;

Output is

(Tacos)

(TomatoSoup)

But I want to get the output as

Recipe

(Tacos)

(TomatoSoup)

Please Suggest

Samle dataset is also attached

1 REPLY 1
Highlighted

Re: PIG Nested Json Query

Guru

@Abhishek Srivastava You will not be able to do this for these reasons:

  • Recipe is the name (or alias) of a field and not the value of the field. In pig you can only retrieve the field values (by referencing their name or position eg $0).
  • In pig you do not have the ability to retrieve headers to the data (field or column names). Only data is returned and you are expected to know the data structure by how you GENERATE it.

Let me know if this answers your question or not, or if you have any followup questions.