Bird
Raised Fist0
Hadoopdata~20 mins

Data serialization (Avro, Parquet, ORC) in Hadoop - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Serialization Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Avro schema validation code?

Given this Avro schema and a JSON record, what will the validation output be?

{
  "type": "record",
  "name": "User",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "age", "type": "int"}
  ]
}

Record: {"name": "Alice", "age": "twenty"}
Hadoop
from fastavro import parse_schema, validate

schema = {
  "type": "record",
  "name": "User",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "age", "type": "int"}
  ]
}

parsed_schema = parse_schema(schema)

record = {"name": "Alice", "age": "twenty"}

is_valid = validate(record, parsed_schema)
print(is_valid)
ATypeError
BTrue
CFalse
DKeyError
Attempts:
2 left
💡 Hint

Check the data types in the record compared to the schema.

❓ data_output
intermediate
2:00remaining
How many rows are stored in this Parquet file snippet?

Assume you read a Parquet file with this Python snippet using PyArrow:

import pyarrow.parquet as pq

pq_file = pq.ParquetFile('data.parquet')
num_rows = pq_file.metadata.num_rows
print(num_rows)

If the file contains 3 row groups with 1000, 1500, and 500 rows respectively, what is the output?

Hadoop
import pyarrow.parquet as pq

pq_file = pq.ParquetFile('data.parquet')
num_rows = pq_file.metadata.num_rows
print(num_rows)
A3000
B1000
C500
D1500
Attempts:
2 left
💡 Hint

Remember that total rows is sum of all row groups.

🔧 Debug
advanced
2:00remaining
Why does this ORC file read code raise an error?

Consider this Python code snippet using pyorc to read an ORC file:

import pyorc

with open('data.orc', 'rb') as file:
    reader = pyorc.Reader(file)
    for row in reader:
        print(row)

The code raises a ValueError: 'Invalid ORC file'. What is the most likely cause?

Hadoop
import pyorc

with open('data.orc', 'rb') as file:
    reader = pyorc.Reader(file)
    for row in reader:
        print(row)
AThe file is not a valid ORC file or is corrupted
BThe file was opened in text mode instead of binary mode
Cpyorc.Reader requires a file path string, not a file object
DThe ORC file is empty, causing the reader to fail
Attempts:
2 left
💡 Hint

Check the file format and integrity before reading.

🧠 Conceptual
advanced
2:00remaining
Which data serialization format supports schema evolution best?

Among Avro, Parquet, and ORC, which format is designed to handle schema changes like adding or removing fields without breaking existing data?

AParquet
BAvro
CORC
DNone of these support schema evolution
Attempts:
2 left
💡 Hint

Think about which format stores schema with data and supports forward/backward compatibility.

🚀 Application
expert
2:00remaining
Which option produces the smallest file size for a large dataset with many repeated string values?

You have a large dataset with many repeated string values in one column. You want to serialize it efficiently using Hadoop-compatible formats. Which format will likely produce the smallest file size?

AORC without compression
BAvro with Snappy compression
CCSV compressed with gzip
DParquet with dictionary encoding and Snappy compression
Attempts:
2 left
💡 Hint

Consider columnar formats and encoding techniques for repeated values.

Practice

(1/5)
1. Which data serialization format stores data in a row-wise manner and includes a schema for each record?
easy
A. Avro
B. Parquet
C. ORC
D. CSV

Solution

  1. Step 1: Understand Avro's storage method

    Avro stores data row-wise, meaning it saves one record at a time along with its schema.
  2. Step 2: Compare with other formats

    Parquet and ORC store data column-wise, optimizing for query speed, while CSV has no schema.
  3. Final Answer:

    Avro -> Option A
  4. Quick Check:

    Row-wise with schema = Avro [OK]
Hint: Row-wise + schema means Avro format [OK]
Common Mistakes:
  • Confusing Parquet or ORC as row-wise
  • Thinking CSV has schema
  • Mixing storage orientation concepts
2. Which of the following is the correct way to specify a Parquet file format in a Hadoop job configuration?
easy
A. job.setOutputFormatClass(TextOutputFormat.class);
B. job.setOutputFormatClass(AvroOutputFormat.class);
C. job.setOutputFormatClass(OrcOutputFormat.class);
D. job.setOutputFormatClass(ParquetOutputFormat.class);

Solution

  1. Step 1: Identify the output format class for Parquet

    Parquet files require setting the output format to ParquetOutputFormat in Hadoop jobs.
  2. Step 2: Eliminate other options

    TextOutputFormat is for text files, AvroOutputFormat for Avro files, and OrcOutputFormat for ORC files.
  3. Final Answer:

    job.setOutputFormatClass(ParquetOutputFormat.class); -> Option D
  4. Quick Check:

    Parquet output format = ParquetOutputFormat [OK]
Hint: Parquet uses ParquetOutputFormat class in Hadoop [OK]
Common Mistakes:
  • Using TextOutputFormat for Parquet files
  • Confusing AvroOutputFormat with ParquetOutputFormat
  • Mixing ORC and Parquet output formats
3. Given the following PySpark code snippet, what will be the output schema of the saved file?
df.write.format('orc').save('/data/output')
medium
A. Data saved in ORC format with schema preserved
B. Data saved in CSV format without schema
C. Data saved in Parquet format with schema preserved
D. Data saved in Avro format with schema preserved

Solution

  1. Step 1: Identify the format used in the code

    The code uses df.write.format('orc'), which means data is saved in ORC format.
  2. Step 2: Understand ORC properties

    ORC stores data column-wise and preserves schema for efficient queries.
  3. Final Answer:

    Data saved in ORC format with schema preserved -> Option A
  4. Quick Check:

    ORC format with schema = Data saved in ORC format with schema preserved [OK]
Hint: format('orc') means ORC with schema saved [OK]
Common Mistakes:
  • Assuming default is CSV
  • Confusing ORC with Parquet or Avro
  • Ignoring schema preservation in ORC
4. You try to read a Parquet file in Spark using this code:
spark.read.format('parquet').load('/data/file.orc')

What is the main issue here?
medium
A. File extension does not match format specified
B. Parquet format cannot read ORC files
C. Spark cannot read Parquet files
D. No issue, code will run fine

Solution

  1. Step 1: Check the file format and extension

    The code tries to read a file with .orc extension using Parquet format.
  2. Step 2: Understand format compatibility

    Parquet reader cannot read ORC files because they have different internal structures.
  3. Final Answer:

    Parquet format cannot read ORC files -> Option B
  4. Quick Check:

    Parquet reader ≠ ORC file [OK]
Hint: Parquet reader can't read ORC files [OK]
Common Mistakes:
  • Ignoring file extension mismatch
  • Assuming Spark auto-detects format
  • Thinking Parquet and ORC are interchangeable
5. You have a large dataset with many columns but only a few are needed for analysis. Which data serialization format is best to optimize query speed and storage, and why?
hard
A. CSV, because it is simple and easy to read
B. Avro, because it stores data row-wise with schema
C. Parquet, because it stores data column-wise allowing fast column queries
D. JSON, because it supports nested data

Solution

  1. Step 1: Understand the dataset and query needs

    Many columns exist but only a few are needed, so reading only those columns is important.
  2. Step 2: Compare serialization formats for columnar access

    Parquet stores data column-wise, enabling fast queries on selected columns and saving storage.
  3. Step 3: Eliminate other options

    Avro is row-wise, so it reads all columns; CSV and JSON lack efficient columnar storage and schema.
  4. Final Answer:

    Parquet, because it stores data column-wise allowing fast column queries -> Option C
  5. Quick Check:

    Column-wise storage = Parquet best for selective queries [OK]
Hint: Column-wise format like Parquet speeds up column queries [OK]
Common Mistakes:
  • Choosing Avro for column queries
  • Picking CSV or JSON for big data efficiency
  • Ignoring storage and query speed trade-offs
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