We use LOAD to bring data into Hadoop, FILTER to pick only the data we want, and STORE to save the results. This helps us work with big data step-by-step.
When you want to read data from a file in Hadoop to analyze it.
When you need to keep only certain rows from a large dataset based on a condition.
When you want to save the filtered or processed data back to Hadoop storage.
When cleaning data by removing unwanted records before further analysis.
When preparing data for another program or step by saving the results.
Syntax
Hadoop
data = LOAD 'input_path' USING PigStorage(',');
filtered_data = FILTER data BY condition;
STORE filtered_data INTO 'output_path' USING PigStorage(',');
LOAD reads data from a file or folder.
FILTER keeps rows where the condition is true.
Examples
Load a CSV file named users.csv into a variable called data.
Hadoop
data = LOAD 'users.csv' USING PigStorage(',');
Keep only rows where the age column is greater than 30.
Hadoop
filtered_data = FILTER data BY age > 30;
Save the filtered data into a folder named users_over_30.
Hadoop
STORE filtered_data INTO 'output/users_over_30' USING PigStorage(',');
Sample Program
This program loads a CSV file with user data, filters users older than 30, and stores the result.
Hadoop
data = LOAD 'input/users.csv' USING PigStorage(',');
filtered_data = FILTER data BY (int)$1 > 30;
STORE filtered_data INTO 'output/users_over_30' USING PigStorage(',');
OutputSuccess
Important Notes
Make sure the input path exists and is accessible in Hadoop.
FILTER conditions must match the data types; cast if needed.
STORE will create a folder; if it exists, Hadoop may throw an error.
Summary
LOAD brings data into Hadoop for processing.
FILTER selects only the rows you want based on a condition.
STORE saves your processed data back to Hadoop storage.
Practice
(1/5)
1. What does the LOAD operation do in Hadoop data processing?
easy
A. Reads data from files into the system
B. Saves data back to storage
C. Filters rows based on a condition
D. Deletes data from storage
Solution
Step 1: Understand the purpose of LOAD
The LOAD operation is used to bring data from external files into the Hadoop processing environment.
Step 2: Differentiate from FILTER and STORE
FILTER selects data rows, and STORE saves data back, so LOAD must be the reading step.
Final Answer:
Reads data from files into the system -> Option A
Quick Check:
LOAD = Read data [OK]
Hint: LOAD means bring data in from files [OK]
Common Mistakes:
Confusing LOAD with STORE operation
Thinking LOAD filters data
Assuming LOAD deletes data
2. Which of the following is the correct syntax to filter rows where age is greater than 30 in Hadoop Pig Latin?
easy
A. filtered_data = LOAD data FILTER age > 30;
B. filtered_data = FILTER data BY age > 30;
C. filtered_data = SELECT * FROM data WHERE age > 30;
D. filtered_data = FILTER data WHERE age > 30;
Solution
Step 1: Recall FILTER syntax in Pig Latin
The correct syntax uses FILTER ... BY to select rows based on a condition.
Step 2: Check each option
A mixes LOAD and FILTER incorrectly; B uses WHERE which is invalid in Pig; C is SQL syntax; D uses FILTER ... BY correctly.
Final Answer:
filtered_data = FILTER data BY age > 30; -> Option B
Quick Check:
FILTER ... BY is correct syntax [OK]
Hint: FILTER uses BY, not WHERE, in Pig Latin [OK]
Common Mistakes:
Using WHERE instead of BY in FILTER
Confusing Pig syntax with SQL
Trying to filter during LOAD
3. Given the following Pig Latin code:
data = LOAD 'users.txt' USING PigStorage(',') AS (name:chararray, age:int);
adults = FILTER data BY age >= 18;
STORE adults INTO 'adult_users';
What will be the content of the 'adult_users' folder?
medium
A. All users from 'users.txt' regardless of age
B. An empty folder because STORE is missing a format
C. Only users with age less than 18
D. Only users with age 18 or older
Solution
Step 1: Understand the FILTER condition
The FILTER selects rows where age is 18 or more, so only adults remain.
Step 2: STORE saves filtered data
The STORE command saves the filtered adults data into 'adult_users' folder.
Final Answer:
Only users with age 18 or older -> Option D
Quick Check:
FILTER age >= 18 then STORE = adults only [OK]
Hint: FILTER keeps only matching rows before STORE [OK]
Common Mistakes:
Assuming STORE saves original data
Thinking STORE needs format specified always
Confusing FILTER condition direction
4. Identify the error in this Pig Latin code snippet:
data = LOAD 'data.txt' USING PigStorage(',');
filtered = FILTER data WHERE score > 50;
STORE filtered INTO 'high_scores';
medium
A. Missing AS clause in LOAD
B. STORE command syntax is incorrect
C. FILTER uses WHERE instead of BY
D. PigStorage should not have parameters
Solution
Step 1: Check FILTER syntax
FILTER in Pig Latin requires BY keyword, not WHERE.
Step 2: Verify other parts
LOAD can omit AS but then schema is unknown; STORE syntax is correct; PigStorage accepts parameters.
Final Answer:
FILTER uses WHERE instead of BY -> Option C
Quick Check:
FILTER ... BY is correct, not WHERE [OK]
Hint: FILTER always uses BY, never WHERE [OK]
Common Mistakes:
Using WHERE in FILTER
Thinking AS is mandatory in LOAD
Misunderstanding PigStorage parameters
5. You have a dataset 'sales.csv' with columns (product, quantity, price). You want to load this data, filter only rows where quantity is greater than 10 and price less than 100, then store the result in 'filtered_sales'. Which Pig Latin code correctly performs this?
hard
A. sales = LOAD 'sales.csv' USING PigStorage(',') AS (product:chararray, quantity:int, price:int); filtered = FILTER sales BY quantity > 10 AND price < 100; STORE filtered INTO 'filtered_sales';
B. sales = LOAD 'sales.csv' USING PigStorage(','); filtered = FILTER sales WHERE quantity > 10 AND price < 100; STORE filtered INTO 'filtered_sales';
C. sales = LOAD 'sales.csv' USING PigStorage(',') AS (product, quantity, price); filtered = FILTER sales BY quantity > 10 OR price < 100; STORE filtered INTO 'filtered_sales';
D. sales = LOAD 'sales.csv' USING PigStorage(',') AS (product:chararray, quantity:int, price:int); filtered = FILTER sales BY quantity > 10 OR price < 100; STORE filtered INTO 'filtered_sales';
Solution
Step 1: Load with schema and correct syntax
sales = LOAD 'sales.csv' USING PigStorage(',') AS (product:chararray, quantity:int, price:int); filtered = FILTER sales BY quantity > 10 AND price < 100; STORE filtered INTO 'filtered_sales'; loads with schema and uses PigStorage correctly.
Step 2: Filter with correct condition and operator
We want quantity > 10 AND price < 100, so AND is correct, not OR.
Step 3: STORE command is correct
sales = LOAD 'sales.csv' USING PigStorage(',') AS (product:chararray, quantity:int, price:int); filtered = FILTER sales BY quantity > 10 AND price < 100; STORE filtered INTO 'filtered_sales'; uses STORE correctly to save filtered data.
Final Answer:
Correct load, filter with AND, and store commands -> Option A
Quick Check:
LOAD with schema + FILTER with AND + STORE = sales = LOAD 'sales.csv' USING PigStorage(',') AS (product:chararray, quantity:int, price:int); filtered = FILTER sales BY quantity > 10 AND price < 100; STORE filtered INTO 'filtered_sales'; [OK]
Hint: Use AND for both conditions, FILTER ... BY, and STORE properly [OK]
Common Mistakes:
Using WHERE instead of BY in FILTER
Using OR instead of AND for filtering
Omitting schema in LOAD causing errors
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.