Bird
Raised Fist0
Hadoopdata~20 mins

Pig vs Hive comparison in Hadoop - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pig vs Hive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Primary Language Used in Pig and Hive
Which language is primarily used to write scripts in Apache Pig and Apache Hive respectively?
APig Latin for Pig and HiveQL for Hive
BSQL for Pig and Java for Hive
CPython for Pig and Pig Latin for Hive
DHiveQL for Pig and Pig Latin for Hive
Attempts:
2 left
💡 Hint
Think about the scripting languages designed specifically for each tool.
🧠 Conceptual
intermediate
1:30remaining
Data Processing Model Difference
What is the main difference in data processing models between Pig and Hive?
ABoth use declarative models but Hive supports more data types
BPig uses a procedural data flow model; Hive uses a declarative SQL-like model
CBoth use procedural models but with different syntax
DPig uses a declarative model; Hive uses a procedural model
Attempts:
2 left
💡 Hint
Consider how users specify data transformations in each tool.
❓ Predict Output
advanced
2:00remaining
Output of Pig Latin Script
What is the output of this Pig Latin script given the input data below?

Input data (file):
1,apple,10
2,banana,20
3,apple,15

Script:
fruit_data = LOAD 'input' USING PigStorage(',') AS (id:int, name:chararray, quantity:int);
apple_data = FILTER fruit_data BY name == 'apple';
total = FOREACH (GROUP apple_data ALL) GENERATE SUM(apple_data.quantity) as total_quantity;
DUMP total;
Hadoop
fruit_data = LOAD 'input' USING PigStorage(',') AS (id:int, name:chararray, quantity:int);
apple_data = FILTER fruit_data BY name == 'apple';
total = FOREACH (GROUP apple_data ALL) GENERATE SUM(apple_data.quantity) as total_quantity;
DUMP total;
A({45})
B({30})
C({15})
D({25})
Attempts:
2 left
💡 Hint
Add the quantities for all rows where name is 'apple'.
❓ Predict Output
advanced
2:00remaining
Hive Query Output for Grouping
Given a Hive table 'fruits' with columns (id INT, name STRING, quantity INT) and data:
1,apple,10
2,banana,20
3,apple,15

What is the output of this HiveQL query?
SELECT name, SUM(quantity) as total_quantity FROM fruits GROUP BY name ORDER BY total_quantity DESC;
Hadoop
SELECT name, SUM(quantity) as total_quantity FROM fruits GROUP BY name ORDER BY total_quantity DESC;
A[('banana', 30), ('apple', 25)]
B[('banana', 20), ('apple', 25)]
C[('apple', 25), ('banana', 20)]
D[('apple', 15), ('banana', 20)]
Attempts:
2 left
💡 Hint
Sum quantities per fruit and order descending by total quantity.
🚀 Application
expert
2:30remaining
Choosing Between Pig and Hive for a Task
You have a large dataset with complex data transformations involving multiple steps and custom functions. You want to write scripts that allow step-by-step data manipulation and debugging. Which tool is more suitable?
APig, because it supports procedural scripts with stepwise transformations and custom functions
BHive, because it supports SQL-like queries and is easier for analysts
CHive, because it is faster for all types of data processing
DPig, because it only supports simple queries and no custom functions
Attempts:
2 left
💡 Hint
Think about which tool is designed for complex data flows and custom code.

Practice

(1/5)
1. Which statement best describes the main difference between Pig and Hive in Hadoop?
easy
A. Pig stores data, Hive processes data.
B. Pig is declarative, and Hive is procedural.
C. Pig is used only for batch processing, Hive only for real-time.
D. Pig uses a scripting language, while Hive uses SQL-like queries.

Solution

  1. Step 1: Understand Pig and Hive languages

    Pig uses a scripting language called Pig Latin, which is procedural. Hive uses a SQL-like declarative language called HiveQL.
  2. Step 2: Compare their query styles

    Pig scripts describe how to process data step-by-step (procedural), while Hive queries describe what data to retrieve (declarative).
  3. Final Answer:

    Pig uses a scripting language, while Hive uses SQL-like queries. -> Option D
  4. Quick Check:

    Language style difference = Pig scripting, Hive SQL [OK]
Hint: Pig = scripting; Hive = SQL-like queries [OK]
Common Mistakes:
  • Confusing procedural and declarative terms
  • Thinking Pig uses SQL
  • Assuming Hive is procedural
2. Which of the following is the correct way to write a simple query in Hive to select all records from a table named users?
easy
A. SELECT * FROM users;
B. LOAD users;
C. FETCH ALL FROM users;
D. GET * FROM users;

Solution

  1. Step 1: Recall Hive query syntax

    Hive uses SQL-like syntax. The standard way to select all records is SELECT * FROM table_name;.
  2. Step 2: Check each option

    SELECT * FROM users; matches the correct SQL syntax. Options A, C, and D are not valid Hive commands.
  3. Final Answer:

    SELECT * FROM users; -> Option A
  4. Quick Check:

    Hive uses SQL syntax = SELECT * FROM [table] [OK]
Hint: Hive queries look like standard SQL SELECT statements [OK]
Common Mistakes:
  • Using non-SQL keywords like LOAD or FETCH for queries
  • Forgetting the FROM keyword
  • Using GET instead of SELECT
3. Given the following Pig script:
data = LOAD 'input' AS (name:chararray, age:int);
filtered = FILTER data BY age > 25;
DUMP filtered;

What will be the output if the input data contains:
('Alice', 30)
('Bob', 22)
('Carol', 27)
medium
A. All three records
B. ('Bob', 22) only
C. ('Alice', 30) and ('Carol', 27)
D. No output

Solution

  1. Step 1: Understand the FILTER condition

    The script filters records where age is greater than 25.
  2. Step 2: Apply filter to input data

    'Alice' (30) and 'Carol' (27) satisfy age > 25; 'Bob' (22) does not.
  3. Final Answer:

    ('Alice', 30) and ('Carol', 27) -> Option C
  4. Quick Check:

    Filter age > 25 = Alice and Carol [OK]
Hint: Filter keeps only records matching condition [OK]
Common Mistakes:
  • Including records with age equal to 25
  • Confusing FILTER with LOAD
  • Assuming all records are output
4. Identify the error in this Hive query:
SELECT name age FROM users WHERE age > 20;
medium
A. Missing comma between selected columns.
B. Incorrect WHERE clause syntax.
C. Table name should be in quotes.
D. SELECT keyword is misspelled.

Solution

  1. Step 1: Analyze the SELECT clause

    The query selects two columns: name and age. They must be separated by a comma.
  2. Step 2: Check the query syntax

    The query misses a comma between 'name' and 'age'. The WHERE clause and table name are correct.
  3. Final Answer:

    Missing comma between selected columns. -> Option A
  4. Quick Check:

    Columns in SELECT need commas [OK]
Hint: Separate columns with commas in SELECT [OK]
Common Mistakes:
  • Omitting commas between columns
  • Adding quotes around table names unnecessarily
  • Miswriting WHERE clause
5. You want to process a complex data flow involving multiple steps of filtering, grouping, and joining large datasets in Hadoop. Which tool is better suited and why?
hard
A. Hive, because it uses SQL and is easier for complex flows.
B. Pig, because it supports procedural scripting for complex data flows.
C. Hive, because it is procedural and faster for joins.
D. Pig, because it only supports simple queries.

Solution

  1. Step 1: Understand tool strengths

    Pig is procedural and designed for complex data flows with multiple steps. Hive is declarative and better for simple querying.
  2. Step 2: Match tool to task

    For complex filtering, grouping, and joining in multiple steps, Pig's scripting is more flexible and suitable.
  3. Final Answer:

    Pig, because it supports procedural scripting for complex data flows. -> Option B
  4. Quick Check:

    Complex flows = Pig scripting [OK]
Hint: Use Pig for complex multi-step data processing [OK]
Common Mistakes:
  • Choosing Hive for complex procedural flows
  • Thinking Pig only supports simple queries
  • Confusing procedural and declarative
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