Search code examples
apache-pig

Fetch the second record from the file using the Pig


My data is like this:

(Alicia,2,Maths,Chemistry,Physics)
(Mac,2,Maths,Chemistry,Botany)
(Hardik,6,Maths,Chemistry,Zoology)
(Maneesh,9,Hindi,Chemistry,Physics)

I want to make a relation which will contain only the second record data, (Mac,2,Maths,Chemistry,Botany) and then I want to perform further operations. I tried using LIMIT command but i will get some records not the specific record.


Solution

  • Use filter for getting specific records.Assuming you have a relation A with the sample dataset, then the below Pig statement will get you the record you are looking for.

    B = FILTER A BY (A.$0 == 'Mac');