Search in sources :

Example 1 with CompressedSplitLineReader

use of org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader in project hydrator-plugins by cdapio.

the class CharsetTransformingLineRecordReaderTest method setUpRecordReaderForTest.

public void setUpRecordReaderForTest(SplitCompressionInputStream splitCompressionInputStream) throws IOException {
    // Set up record reader to assume we'll read the file from the beggining, and the partition size is 32 bytes
    // which is 8 characters in UTF-32, meaning we expect to read the first 2 lines for this partition.
    recordReader = spy(new CharsetTransformingLineRecordReader(fixedLengthCharset, null, new CompressedSplitLineReader(splitCompressionInputStream, conf, null), 0, 0, 32, 4096));
    // We will calculate position based on the number of bytes consumed from the input stream.
    doAnswer(a -> (long) availableBytes - inputStream.available()).when(recordReader).getFilePosition();
}
Also used : CompressedSplitLineReader(org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader)

Example 2 with CompressedSplitLineReader

use of org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader in project hydrator-plugins by cdapio.

the class CharsetTransformingLineRecordReader method initialize.

/**
 * Initialize method from parent class, simplified for this our use case from the base class.
 *
 * @param genericSplit File Split
 * @param context      Execution context
 * @throws IOException if the underlying file or decompression operations fail.
 */
public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException {
    FileSplit split = (FileSplit) genericSplit;
    Configuration job = context.getConfiguration();
    this.maxLineLength = job.getInt(MAX_LINE_LENGTH, Integer.MAX_VALUE);
    start = split.getStart();
    end = start + split.getLength();
    final Path file = split.getPath();
    // open the file and seek to the start of the split
    final FileSystem fs = file.getFileSystem(job);
    FSDataInputStream fileIn = fs.open(file);
    SplittableCompressionCodec codec = new FixedLengthCharsetTransformingCodec(fixedLengthCharset);
    decompressor = codec.createDecompressor();
    final SplitCompressionInputStream cIn = codec.createInputStream(fileIn, decompressor, start, end, SplittableCompressionCodec.READ_MODE.CONTINUOUS);
    in = new CompressedSplitLineReader(cIn, job, this.recordDelimiterBytes);
    start = cIn.getAdjustedStart();
    end = cIn.getAdjustedEnd();
    filePosition = cIn;
    // next() method.
    if (start != 0) {
        Text t = new Text();
        start += in.readLine(t, 4096, Integer.MAX_VALUE);
        LOG.info("Discarded line: " + t.toString());
    }
    this.pos = start;
}
Also used : Path(org.apache.hadoop.fs.Path) SplittableCompressionCodec(org.apache.hadoop.io.compress.SplittableCompressionCodec) Configuration(org.apache.hadoop.conf.Configuration) SplitCompressionInputStream(org.apache.hadoop.io.compress.SplitCompressionInputStream) FixedLengthCharsetTransformingCodec(io.cdap.plugin.format.charset.fixedlength.FixedLengthCharsetTransformingCodec) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) CompressedSplitLineReader(org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader) Text(org.apache.hadoop.io.Text) FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit)

Example 3 with CompressedSplitLineReader

use of org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader in project shifu by ShifuML.

the class CombineRecordReader method initializeOne.

public void initializeOne(FileSplit split, TaskAttemptContext context) throws IOException {
    Configuration job = context.getConfiguration();
    this.maxLineLength = job.getInt(MAX_LINE_LENGTH, Integer.MAX_VALUE);
    start = split.getStart();
    end = start + split.getLength();
    final Path file = split.getPath();
    // open the file and seek to the start of the split
    final FileSystem fs = file.getFileSystem(job);
    fileIn = fs.open(file);
    CompressionCodec codec = new CompressionCodecFactory(job).getCodec(file);
    if (null != codec) {
        isCompressedInput = true;
        decompressor = CodecPool.getDecompressor(codec);
        if (codec instanceof SplittableCompressionCodec) {
            final SplitCompressionInputStream cIn = ((SplittableCompressionCodec) codec).createInputStream(fileIn, decompressor, start, end, SplittableCompressionCodec.READ_MODE.BYBLOCK);
            in = new CompressedSplitLineReader(cIn, job, this.recordDelimiterBytes);
            start = cIn.getAdjustedStart();
            end = cIn.getAdjustedEnd();
            filePosition = cIn;
        } else {
            in = new SplitLineReader(codec.createInputStream(fileIn, decompressor), job, this.recordDelimiterBytes);
            filePosition = fileIn;
        }
    } else {
        fileIn.seek(start);
        in = new SplitLineReader(fileIn, job, this.recordDelimiterBytes);
        filePosition = fileIn;
    }
    // next() method.
    if (start != 0) {
        start += in.readLine(new Text(), 0, maxBytesToConsume(start));
    }
    this.pos = start;
}
Also used : Path(org.apache.hadoop.fs.Path) SplitLineReader(org.apache.hadoop.mapreduce.lib.input.SplitLineReader) CompressedSplitLineReader(org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader) SplittableCompressionCodec(org.apache.hadoop.io.compress.SplittableCompressionCodec) Configuration(org.apache.hadoop.conf.Configuration) CompressionCodecFactory(org.apache.hadoop.io.compress.CompressionCodecFactory) SplitCompressionInputStream(org.apache.hadoop.io.compress.SplitCompressionInputStream) FileSystem(org.apache.hadoop.fs.FileSystem) CompressedSplitLineReader(org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader) Text(org.apache.hadoop.io.Text) CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) SplittableCompressionCodec(org.apache.hadoop.io.compress.SplittableCompressionCodec)

Aggregations

CompressedSplitLineReader (org.apache.hadoop.mapreduce.lib.input.CompressedSplitLineReader)3 Configuration (org.apache.hadoop.conf.Configuration)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Text (org.apache.hadoop.io.Text)2 SplitCompressionInputStream (org.apache.hadoop.io.compress.SplitCompressionInputStream)2 SplittableCompressionCodec (org.apache.hadoop.io.compress.SplittableCompressionCodec)2 FixedLengthCharsetTransformingCodec (io.cdap.plugin.format.charset.fixedlength.FixedLengthCharsetTransformingCodec)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)1 CompressionCodecFactory (org.apache.hadoop.io.compress.CompressionCodecFactory)1 FileSplit (org.apache.hadoop.mapreduce.lib.input.FileSplit)1 SplitLineReader (org.apache.hadoop.mapreduce.lib.input.SplitLineReader)1