Bird
Raised Fist0
Hadoopdata~10 mins

Compression codecs (Snappy, LZO, Gzip) in Hadoop - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the Snappy compression codec in Hadoop configuration.

Hadoop
conf.set("mapreduce.output.fileoutputformat.compress.codec", [1])
Drag options to blanks, or click blank then click option'
A"org.apache.hadoop.io.compress.DefaultCodec"
B"org.apache.hadoop.io.compress.GzipCodec"
C"org.apache.hadoop.io.compress.SnappyCodec"
D"org.apache.hadoop.io.compress.Lz4Codec"
Attempts:
3 left
💡 Hint
Common Mistakes
Using Gzip codec class instead of Snappy.
Using Lz4 codec which is different from LZO.
Forgetting to put quotes around the class name.
2fill in blank
medium

Complete the code to enable compression for MapReduce output.

Hadoop
conf.setBoolean("mapreduce.output.fileoutputformat.compress", [1])
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C"true"
D"false"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing string 'true' instead of boolean true.
Passing false which disables compression.
3fill in blank
hard

Fix the error in setting the LZO codec class name for compression.

Hadoop
conf.set("mapreduce.output.fileoutputformat.compress.codec", [1])
Drag options to blanks, or click blank then click option'
A"com.hadoop.compression.lzo.LzopCodec"
B"org.apache.hadoop.io.compress.LzoCodec"
C"org.apache.hadoop.io.compress.LzopCodec"
D"com.hadoop.compression.lzo.LzoCodec"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'LzopCodec' instead of 'LzoCodec'.
Using 'org.apache.hadoop.io.compress' package for LZO.
4fill in blank
hard

Fill both blanks to create a configuration snippet that enables Gzip compression and sets the codec.

Hadoop
conf.setBoolean("mapreduce.output.fileoutputformat.compress", [1])
conf.set("mapreduce.output.fileoutputformat.compress.codec", [2])
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C"org.apache.hadoop.io.compress.GzipCodec"
D"org.apache.hadoop.io.compress.SnappyCodec"
Attempts:
3 left
💡 Hint
Common Mistakes
Disabling compression but setting codec.
Setting Snappy codec instead of Gzip.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps codec names to their class names for Snappy, LZO, and Gzip.

Hadoop
codecs = {"Snappy": [1], "LZO": [2], "Gzip": [3]
Drag options to blanks, or click blank then click option'
A"org.apache.hadoop.io.compress.SnappyCodec"
B"com.hadoop.compression.lzo.LzoCodec"
C"org.apache.hadoop.io.compress.GzipCodec"
D"org.apache.hadoop.io.compress.DefaultCodec"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up codec class names.
Using DefaultCodec instead of specific codecs.

Practice

(1/5)
1. Which compression codec is known for the fastest compression and decompression speed in Hadoop?
easy
A. LZO
B. Gzip
C. Snappy
D. Bzip2

Solution

  1. Step 1: Understand codec speed characteristics

    Snappy is designed for speed, offering fast compression and decompression.
  2. Step 2: Compare with other codecs

    Gzip compresses better but slower; LZO is fast but usually slower than Snappy; Bzip2 is slowest.
  3. Final Answer:

    Snappy -> Option C
  4. Quick Check:

    Fastest codec = Snappy [OK]
Hint: Snappy is fastest codec for speed, not best compression [OK]
Common Mistakes:
  • Confusing Gzip as fastest due to better compression
  • Thinking LZO is faster than Snappy
  • Assuming Bzip2 is fast
2. Which of the following is the correct way to enable Snappy compression in a Hadoop job configuration XML?
easy
A. mapreduce.output.fileoutputformat.compress.codecorg.apache.hadoop.io.compress.GzipCodec
B. mapreduce.output.fileoutputformat.compress.codecorg.apache.hadoop.io.compress.SnappyCodec
C. mapreduce.output.fileoutputformat.compress.codecorg.apache.hadoop.io.compress.Lz4Codec
D. mapreduce.output.fileoutputformat.compress.codecorg.apache.hadoop.io.compress.Bzip2Codec

Solution

  1. Step 1: Identify the property for compression codec

    The property key is 'mapreduce.output.fileoutputformat.compress.codec' to set codec class.
  2. Step 2: Match the codec class for Snappy

    Snappy codec class is 'org.apache.hadoop.io.compress.SnappyCodec'.
  3. Final Answer:

    Property with SnappyCodec class -> Option B
  4. Quick Check:

    Snappy codec class = org.apache.hadoop.io.compress.SnappyCodec [OK]
Hint: Snappy codec class ends with SnappyCodec [OK]
Common Mistakes:
  • Using GzipCodec or other codec classes by mistake
  • Misspelling the property name
  • Confusing Lz4Codec with LZO
3. Given the following Hadoop job configuration snippet, what compression codec will be used?
conf.set("mapreduce.output.fileoutputformat.compress", "true");
conf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.GzipCodec");
medium
A. Snappy
B. LZO
C. No compression
D. Gzip

Solution

  1. Step 1: Check if compression is enabled

    Property 'mapreduce.output.fileoutputformat.compress' is set to 'true', so compression is enabled.
  2. Step 2: Identify the codec class used

    Codec class is 'org.apache.hadoop.io.compress.GzipCodec', which means Gzip compression is used.
  3. Final Answer:

    Gzip -> Option D
  4. Quick Check:

    Compression enabled with Gzip codec [OK]
Hint: Check compress property true + codec class name [OK]
Common Mistakes:
  • Ignoring the compress flag and assuming no compression
  • Confusing codec class with Snappy or LZO
  • Assuming default codec if not checked
4. You configured LZO compression in your Hadoop job, but the job fails with a codec not found error. What is the most likely cause?
medium
A. LZO native libraries are not installed or not in the library path
B. The job configuration property name is misspelled
C. Snappy codec is enabled instead of LZO
D. Gzip compression is incompatible with Hadoop

Solution

  1. Step 1: Understand LZO codec requirements

    LZO requires native libraries installed on all cluster nodes to work properly.
  2. Step 2: Analyze error cause

    Codec not found error usually means native LZO libraries are missing or not accessible in the library path.
  3. Final Answer:

    LZO native libraries missing or not in path -> Option A
  4. Quick Check:

    LZO needs native libs installed [OK]
Hint: LZO needs native libs installed on cluster nodes [OK]
Common Mistakes:
  • Assuming misspelled property causes codec not found
  • Confusing Snappy and LZO codec errors
  • Thinking Gzip is incompatible with Hadoop
5. You want to compress large Hadoop output files with the best compression ratio but can tolerate slower speed. Which codec should you choose and why?
hard
A. Gzip, because it offers the best compression ratio despite slower speed
B. LZO, because it balances speed and compression
C. Snappy, because it is fastest and good compression
D. No compression, to avoid overhead

Solution

  1. Step 1: Identify compression needs

    Best compression ratio means smallest file size, speed is less important.
  2. Step 2: Compare codecs by compression ratio and speed

    Gzip compresses better but slower; Snappy is fastest but less compression; LZO is in between.
  3. Step 3: Choose codec matching needs

    Gzip fits best for high compression ratio with slower speed tolerance.
  4. Final Answer:

    Gzip, best compression ratio with slower speed -> Option A
  5. Quick Check:

    Best compression ratio = Gzip [OK]
Hint: Best compression ratio usually means Gzip codec [OK]
Common Mistakes:
  • Choosing Snappy for best compression ratio
  • Thinking LZO compresses better than Gzip
  • Avoiding compression despite need to save space
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