Bird
Raised Fist0
Hadoopdata~30 mins

LOAD, FILTER, and STORE operations in Hadoop - Mini Project: Build & Apply

Choose your learning style10 modes available
LOAD, FILTER, and STORE operations
📖 Scenario: You work with a large dataset of customer orders stored in Hadoop. You want to load this data, filter orders with amounts greater than 100, and save the filtered results for further analysis.
🎯 Goal: Build a Hadoop Pig script that loads the orders data, filters orders with amount greater than 100, and stores the filtered data into a new location.
📋 What You'll Learn
Load data from '/data/orders' with fields order_id, customer_id, and amount
Create a filter condition to keep only orders where amount > 100
Store the filtered results into '/data/filtered_orders'
💡 Why This Matters
🌍 Real World
Filtering large datasets in Hadoop is common for preparing data for analysis or reporting.
💼 Career
Data engineers and analysts use LOAD, FILTER, and STORE operations daily to manage big data pipelines.
Progress0 / 4 steps
1
Load the orders data
Write a Pig Latin statement to load the data from '/data/orders' into a relation called orders. The data has three fields: order_id, customer_id, and amount.
Hadoop
Hint

Use LOAD with PigStorage and define the schema with AS.

2
Filter orders with amount greater than 100
Create a new relation called filtered_orders by filtering orders to keep only rows where amount > 100.
Hadoop
Hint

Use FILTER with the condition amount > 100.

3
Store the filtered orders
Write a statement to store the filtered_orders relation into the directory '/data/filtered_orders' using PigStorage with comma separator.
Hadoop
Hint

Use STORE with PigStorage to save the filtered data.

4
Display the filtered orders
Write a statement to dump the filtered_orders relation to display the filtered data on the console.
Hadoop
Hint

Use DUMP to print the filtered data.

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