Bird
Raised Fist0
Hadoopdata~10 mins

LOAD, FILTER, and STORE operations in Hadoop - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - LOAD, FILTER, and STORE operations
LOAD data from source
↓
FILTER data by condition
↓
STORE filtered data to destination
↓
END
Data is first loaded from a source, then filtered by a condition, and finally stored to a destination.
Execution Sample
Hadoop
data = LOAD 'input.txt';
filtered = FILTER data BY age > 30;
STORE filtered INTO 'output';
Load data from 'input.txt', keep only rows where age is greater than 30, then save the result to 'output'.
Execution Table
StepOperationInput DataCondition/ActionOutput Data
1LOADNoneRead all rows from 'input.txt'[{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}]
2FILTER[{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}]Keep rows where age > 30[{'name':'Bob','age':35},{'name':'Cara','age':40}]
3STORE[{'name':'Bob','age':35},{'name':'Cara','age':40}]Write data to 'output'Data saved to 'output'
4ENDN/AAll steps completedProcess finished
💡 Process stops after storing filtered data to 'output'.
Variable Tracker
VariableStartAfter LOADAfter FILTERAfter STORE
dataNone[{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}][{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}][{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}]
filteredNoneNone[{'name':'Bob','age':35},{'name':'Cara','age':40}][{'name':'Bob','age':35},{'name':'Cara','age':40}]
Key Moments - 3 Insights
Why does the 'filtered' variable only contain some rows after the FILTER step?
Because FILTER keeps only rows where the condition 'age > 30' is true, as shown in execution_table step 2.
Does the original 'data' variable change after filtering?
No, 'data' remains the same after FILTER; filtering creates a new variable 'filtered' as seen in variable_tracker.
What happens if STORE is not called after FILTER?
The filtered data would not be saved anywhere; execution_table step 3 shows STORE writes data to 'output'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output data after the FILTER operation?
A[{'name':'Bob','age':35},{'name':'Cara','age':40}]
B[{'name':'Ann','age':25}]
C[{'name':'Ann','age':25},{'name':'Bob','age':35},{'name':'Cara','age':40}]
D[]
💡 Hint
Check the 'Output Data' column at Step 2 in the execution_table.
At which step does the data get saved to the destination?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look for the STORE operation in the execution_table.
If the FILTER condition changed to 'age > 40', what would be the output after filtering?
A[{'name':'Bob','age':35}]
B[{'name':'Cara','age':40}]
C[]
D[{'name':'Ann','age':25}]
💡 Hint
Refer to how FILTER selects rows based on the condition in execution_table step 2.
Concept Snapshot
LOAD reads data from a source file.
FILTER keeps only rows matching a condition.
STORE saves the filtered data to a destination.
Each step produces new data without changing original.
Used together to process and save specific data subsets.
Full Transcript
This lesson shows how Hadoop LOAD, FILTER, and STORE operations work step-by-step. First, data is loaded from a file, reading all rows. Then, FILTER keeps only rows where the age is greater than 30. Finally, STORE saves the filtered data to an output location. Variables 'data' and 'filtered' track the data before and after filtering. The process stops after storing the filtered data. Key points include that FILTER creates a new dataset without changing the original, and STORE writes data to disk. The visual quiz tests understanding of outputs at each step and effects of changing filter conditions.

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

  1. Step 1: Understand the purpose of LOAD

    The LOAD operation is used to bring data from external files into the Hadoop processing environment.
  2. Step 2: Differentiate from FILTER and STORE

    FILTER selects data rows, and STORE saves data back, so LOAD must be the reading step.
  3. Final Answer:

    Reads data from files into the system -> Option A
  4. 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

  1. Step 1: Recall FILTER syntax in Pig Latin

    The correct syntax uses FILTER ... BY to select rows based on a condition.
  2. 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.
  3. Final Answer:

    filtered_data = FILTER data BY age > 30; -> Option B
  4. 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

  1. Step 1: Understand the FILTER condition

    The FILTER selects rows where age is 18 or more, so only adults remain.
  2. Step 2: STORE saves filtered data

    The STORE command saves the filtered adults data into 'adult_users' folder.
  3. Final Answer:

    Only users with age 18 or older -> Option D
  4. 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

  1. Step 1: Check FILTER syntax

    FILTER in Pig Latin requires BY keyword, not WHERE.
  2. Step 2: Verify other parts

    LOAD can omit AS but then schema is unknown; STORE syntax is correct; PigStorage accepts parameters.
  3. Final Answer:

    FILTER uses WHERE instead of BY -> Option C
  4. 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

  1. 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.
  2. Step 2: Filter with correct condition and operator

    We want quantity > 10 AND price < 100, so AND is correct, not OR.
  3. 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.
  4. Final Answer:

    Correct load, filter with AND, and store commands -> Option A
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard