Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributed file processing in Hadoop?

I have a large number of compressed tar files, where each tar itself contains several files. I want to extract these files and I want to use hadoop or a similar technique to speedup the the processing. Are there any tools for this kind of problem? As far as I know hadoop and similar frameworks like spark or flink do not use files directly and don't give you access to the filesystem directly. I also want to do some basic renaming of the extracted files and move them into appropriate directories.

I can image a solution where one creates a list of all tar files. This list is then passed to the mappers and a single mapper extracts one file from the list. Is this a reasonable approach?

like image 747
headmyshoulder Avatar asked Jul 31 '26 13:07

headmyshoulder


1 Answers

It is possible to instruct MapReduce to use an input format where the input to each Mapper is a single file. (from https://code.google.com/p/hadoop-course/source/browse/HadoopSamples/src/main/java/mr/wholeFile/WholeFileInputFormat.java?r=3)

public class WholeFileInputFormat extends FileInputFormat<NullWritable, BytesWritable> {

  @Override
  protected boolean isSplitable(JobContext context, Path filename) {
    return false;
  }

  @Override
  public RecordReader<NullWritable, BytesWritable> createRecordReader(
    InputSplit inputSplit, TaskAttemptContext context) throws IOException,
  InterruptedException {
    WholeFileRecordReader reader = new WholeFileRecordReader();
    reader.initialize(inputSplit, context);
    return reader;
  }
}

Then, in your mapper, you can use the Apache commons compress library to unpack the tar file https://commons.apache.org/proper/commons-compress/examples.html

you don't need to pass a list of files to Hadoop, just put all the files in a single HDFS directory, and use that directory as your input path.

like image 107
mattinbits Avatar answered Aug 02 '26 08:08

mattinbits