Search in sources :

Example 1 with BSONFileRecordReader

use of com.mongodb.hadoop.mapred.input.BSONFileRecordReader in project mongo-hadoop by mongodb.

the class BSONFileInputFormat method getRecordReader.

@Override
public RecordReader<NullWritable, BSONWritable> getRecordReader(final InputSplit split, final JobConf job, final Reporter reporter) throws IOException {
    FileSplit fileSplit = (FileSplit) split;
    FileSystem fs = FileSystem.get(fileSplit.getPath().toUri(), job);
    if (split instanceof BSONFileSplit || !isSplitable(fs, fileSplit.getPath())) {
        BSONFileRecordReader reader = new BSONFileRecordReader();
        reader.initialize(split, job);
        return reader;
    }
    // Split was not created by BSONSplitter.
    BSONSplitter splitter = new BSONSplitter();
    splitter.setConf(job);
    splitter.setInputPath(fileSplit.getPath());
    org.apache.hadoop.mapreduce.lib.input.FileSplit newStyleFileSplit = new org.apache.hadoop.mapreduce.lib.input.FileSplit(fileSplit.getPath(), fileSplit.getStart(), fileSplit.getLength(), fileSplit.getLocations());
    long start = splitter.getStartingPositionForSplit(newStyleFileSplit);
    BSONFileRecordReader reader = new BSONFileRecordReader(start);
    reader.initialize(fileSplit, job);
    return reader;
}
Also used : BSONFileSplit(com.mongodb.hadoop.mapred.input.BSONFileSplit) BSONFileSplit(com.mongodb.hadoop.mapred.input.BSONFileSplit) FileSplit(org.apache.hadoop.mapred.FileSplit) BSONSplitter(com.mongodb.hadoop.splitter.BSONSplitter) BSONFileRecordReader(com.mongodb.hadoop.mapred.input.BSONFileRecordReader) FileSystem(org.apache.hadoop.fs.FileSystem)

Aggregations

BSONFileRecordReader (com.mongodb.hadoop.mapred.input.BSONFileRecordReader)1 BSONFileSplit (com.mongodb.hadoop.mapred.input.BSONFileSplit)1 BSONSplitter (com.mongodb.hadoop.splitter.BSONSplitter)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 FileSplit (org.apache.hadoop.mapred.FileSplit)1