Professional Documents
Culture Documents
Pig Questions
Pig Questions
Pig Questions
Q1. Consider the student data file (st.txt) Data in the following format Name, District; Age,
Gender:
i. Write a PIG Script to display Names of all male students.
ii. Write a PIG Script to find the number of students from Ghaziabad district.
iii. Write a PIG Script to display district wise count of all female students.
Ans.
3. Write a PIG Script to find the number of students from Ghaziabad district.
4. Write a PIG Script to display district wise count of all female students.
Ans.
Step I: Load the data from HDFS
input = LOAD '/path/to/file/' AS(line:Chararray);
Step II: Convert the Sentence into words
(TOKENIZE(line,' '));
O/P:
({(This),(is),(a),(hadoop),(class)})
({(hadoop),(is),(a),(bigdata),(technology)})
Step III: Convert Column into Rows
Words = FOREACH input GENERATE FLATTEN(TOKENIZE(line,' ')) AS word;
O/P:
(This)
(is)
(a)
(hadoop)
(class)
(hadoop)
(is)
(a)
(bigdata)
(technology)
Q3. Consider the given information analyze the twitter data and explain the steps involved to
find how many tweets are created by a user using Pig latin.
Ans: