Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read Snappy compressed files on HDFS without using Hadoop?

I'm storing files on HDFS in Snappy compression format. I'd like to be able to examine these files on my local Linux file system to make sure that the Hadoop process that created them has performed correctly.

When I copy them locally and attempt to de-compress them with the Google standard libarary, it tells me that the file is missing the Snappy identifier. When I try to go around this by inserting a Snappy identifier, it messes up the checksum.

What can I do to read these files without having to write a separate Hadoop program or pass it through something like Hive?

like image 232
Robert Rapplean Avatar asked May 21 '13 16:05

Robert Rapplean


2 Answers

I finally found out that I can use the following command to read the contents of a Snappy compressed file on HDFS:

hadoop fs -text /path/filename

Using the latest commands on Cloudera or HDP:

hdfs dfs -text /path/filename

If the intent is to download the file in text format for additional examination and processing, the output of that command can be piped to a file on the local system. You can also use head to just view the first few lines of the file.

like image 106
Robert Rapplean Avatar answered Sep 25 '22 09:09

Robert Rapplean


Please take a look at this post on Cloudera blog. It explains how to use Snappy with Hadoop. Essentially, Snappy files on raw text are not splittable, so you cannot read a single file across multiple hosts.

The solution is to use Snappy in a container format, so essentially you're using Hadoop SequenceFile with compression set as Snappy. As described in this answer, you can set the property mapred.output.compression.codec to org.apache.hadoop.io.compress.SnappyCodec and setup your job output format as SequenceFileOutputFormat.

And then to read it, you should only need to use SequenceFile.Reader because the codec information is stored in the file header.

like image 34
Charles Menguy Avatar answered Sep 24 '22 09:09

Charles Menguy