Pig Latin is a simple scripting language used with Apache Pig to process and analyze large data sets on Hadoop. It makes writing MapReduce jobs easier by using a high-level language.
Click to reveal answer
beginner
How do you load data into Pig Latin?
You use the LOAD statement to read data from the Hadoop file system into a relation. For example: data = LOAD 'input.txt' USING PigStorage(',');
Click to reveal answer
beginner
What is a relation in Pig Latin?
A relation is like a table or dataset in Pig Latin. It holds rows of data and can be transformed with operations like FILTER, GROUP, and JOIN.
Click to reveal answer
beginner
How do you filter data in Pig Latin?
You use the FILTER statement to select rows that meet a condition. For example: filtered_data = FILTER data BY age > 30; selects rows where age is greater than 30.
Click to reveal answer
beginner
How do you store the results of a Pig Latin script?
You use the STORE statement to save the output relation back to the Hadoop file system. For example: STORE filtered_data INTO 'output' USING PigStorage(',');
Click to reveal answer
Which statement is used to read data into Pig Latin?
ALOAD
BSTORE
CFILTER
DJOIN
✗ Incorrect
LOAD reads data from the Hadoop file system into a Pig relation.
What does the FILTER statement do in Pig Latin?
AJoins two datasets
BSelects rows based on a condition
CSaves data to disk
DLoads data from HDFS
✗ Incorrect
FILTER selects rows that meet a specified condition.
In Pig Latin, what is a relation?
AA Hadoop cluster
BA type of file
CA function
DA dataset or table
✗ Incorrect
A relation is a dataset or table holding rows of data.
Which statement saves the output of a Pig Latin script?
ALOAD
BFILTER
CSTORE
DGROUP
✗ Incorrect
STORE saves the processed data back to the Hadoop file system.
What is the main purpose of Pig Latin?
ATo simplify writing MapReduce jobs
BTo write complex Java code
CTo manage Hadoop clusters
DTo store data in HDFS
✗ Incorrect
Pig Latin simplifies writing MapReduce jobs with a high-level scripting language.
Explain how you would load, filter, and store data using Pig Latin.
Think about the sequence: read data, select rows, save results.
You got /4 concepts.
Describe what a relation is in Pig Latin and why it is important.
Relations hold your data and let you apply operations.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the FILTER statement in Pig Latin?
easy
A. To select rows that meet a condition
B. To combine two datasets
C. To load data from a file
D. To save the results to storage
Solution
Step 1: Understand the role of FILTER
The FILTER statement is used to keep only the rows that satisfy a given condition.
Step 2: Compare with other statements
LOAD reads data, GROUP groups data, STORE saves data, so FILTER is for selecting rows.
Final Answer:
To select rows that meet a condition -> Option A
Quick Check:
FILTER = select rows [OK]
Hint: FILTER keeps rows matching condition, like a sieve [OK]
Common Mistakes:
Confusing FILTER with GROUP
Thinking FILTER saves data
Mixing FILTER with LOAD
2. Which of the following is the correct syntax to load a file named data.txt in Pig Latin?
easy
A. LOAD 'data.txt' USING PigStorage();
B. LOAD data.txt USING PigStorage();
C. LOAD 'data.txt' AS PigStorage();
D. LOAD 'data.txt' USING PigStorage
Solution
Step 1: Check the LOAD syntax
LOAD requires the file path as a string in quotes and the loader function with parentheses.
Step 2: Validate each option
LOAD 'data.txt' USING PigStorage(); uses quotes and parentheses correctly. LOAD data.txt USING PigStorage(); misses quotes. LOAD 'data.txt' AS PigStorage(); uses AS instead of USING. LOAD 'data.txt' USING PigStorage misses parentheses.
Final Answer:
LOAD 'data.txt' USING PigStorage(); -> Option A
Quick Check:
LOAD 'file' USING loader(); [OK]
Hint: LOAD needs quotes and parentheses for loader [OK]
Common Mistakes:
Forgetting quotes around filename
Using AS instead of USING
Omitting parentheses after loader
3. Given the following Pig Latin code:
A = LOAD 'numbers.txt' USING PigStorage(',');
B = FILTER A BY $0 > 10;
C = FOREACH B GENERATE $0;
DUMP C;
What will be the output if numbers.txt contains: 5,abc 15,def 8,ghi 20,jkl
medium
A. (5,abc)
(8,ghi)
B. (5)
(8)
C. (15,def)
(20,jkl)
D. (15)
(20)
Solution
Step 1: Understand the FILTER condition
FILTER keeps rows where first column ($0) is greater than 10, so rows with 15 and 20 remain.
Step 2: Understand FOREACH GENERATE
FOREACH selects only the first column ($0), so output shows only 15 and 20 as single values.
Final Answer:
(15)
(20) -> Option D
Quick Check:
FILTER $0 > 10 then select $0 [OK]
Hint: FILTER then FOREACH select column shows filtered values [OK]
Common Mistakes:
Including second column in output
Selecting rows less than or equal to 10
Confusing FILTER condition
4. Identify the error in this Pig Latin script:
data = LOAD 'input.txt' USING PigStorage(',');
filtered = FILTER data BY $1 == 'USA';
grouped = GROUP filtered BY $2;
result = FOREACH grouped GENERATE group, COUNT(filtered);
STORE result INTO 'output';
medium
A. COUNT should use filtered instead of group
B. STORE command missing USING clause
C. FILTER condition uses wrong column index
D. GROUP should use filtered instead of data
Solution
Step 1: Check STORE syntax
STORE requires a USING clause to specify the storage format, e.g., PigStorage().
Step 2: Verify other statements
GROUP uses filtered correctly, COUNT uses filtered correctly, FILTER condition is valid if $1 is country column.
Final Answer:
STORE command missing USING clause -> Option B
Quick Check:
STORE ... INTO 'path' USING loader() [OK]
Hint: STORE needs USING clause to save data [OK]
Common Mistakes:
Omitting USING in STORE
Confusing GROUP input
Misunderstanding COUNT argument
5. You have a dataset of sales with columns: product_id, region, amount. You want to find total sales per region but only for sales above 100. Which Pig Latin sequence correctly achieves this?
hard
A. A = LOAD 'sales.txt' USING PigStorage(',');
B = FILTER A BY amount > 100;
C = GROUP B BY region;
D = FOREACH C GENERATE group, SUM(B.amount);
STORE D INTO 'result' USING PigStorage();
B. A = LOAD 'sales.txt' USING PigStorage(',');
B = FILTER A BY $2 > 100;
C = GROUP B BY $1;
D = FOREACH C GENERATE group, SUM(B.$2);
STORE D INTO 'result';
C. A = LOAD 'sales.txt' USING PigStorage(',');
B = FILTER A BY $2 > 100;
C = GROUP B BY $1;
D = FOREACH C GENERATE group, SUM(B.$2);
STORE D INTO 'result' USING PigStorage();
D. A = LOAD 'sales.txt' USING PigStorage(',');
B = FILTER A BY $1 > 100;
C = GROUP B BY $2;
D = FOREACH C GENERATE group, SUM(B.$3);
STORE D INTO 'result' USING PigStorage();
Solution
Step 1: Identify correct column indexes
Columns: product_id ($0), region ($1), amount ($2). Filter by amount > 100 means FILTER BY $2 > 100.
Step 2: Group by region and sum amount
Group by $1 (region), then sum B.$2 (amount) in FOREACH. STORE needs USING clause.
Step 3: Check each option
A = LOAD 'sales.txt' USING PigStorage(',');
B = FILTER A BY $2 > 100;
C = GROUP B BY $1;
D = FOREACH C GENERATE group, SUM(B.$2);
STORE D INTO 'result' USING PigStorage(); matches all requirements: correct filter, group, sum, and STORE syntax.
Final Answer:
Option C code sequence -> Option C
Quick Check:
Filter $2>100, group $1, sum $2, STORE with USING [OK]
Hint: Use correct column indexes and STORE with USING [OK]
Common Mistakes:
Using wrong column indexes for filter or group
Omitting USING in STORE
Summing wrong column
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.