Search in sources :

Example 1 with Int32ValuesDecoder

use of com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder in project presto by prestodb.

the class Int32NestedBatchReader method readNestedWithNull.

@Override
protected ColumnChunk readNestedWithNull() throws IOException {
    int maxDefinitionLevel = columnDescriptor.getMaxDefinitionLevel();
    RepetitionLevelDecodingContext repetitionLevelDecodingContext = readRepetitionLevels(nextBatchSize);
    DefinitionLevelDecodingContext definitionLevelDecodingContext = readDefinitionLevels(repetitionLevelDecodingContext.getDLValuesDecoderContexts(), repetitionLevelDecodingContext.getRepetitionLevels().length);
    int[] definitionLevels = definitionLevelDecodingContext.getDefinitionLevels();
    int newBatchSize = 0;
    int batchNonNullCount = 0;
    for (ValuesDecoderContext valuesDecoderContext : definitionLevelDecodingContext.getValuesDecoderContexts()) {
        int nonNullCount = 0;
        int valueCount = 0;
        for (int i = valuesDecoderContext.getStart(); i < valuesDecoderContext.getEnd(); i++) {
            nonNullCount += (definitionLevels[i] == maxDefinitionLevel ? 1 : 0);
            valueCount += (definitionLevels[i] >= maxDefinitionLevel - 1 ? 1 : 0);
        }
        batchNonNullCount += nonNullCount;
        newBatchSize += valueCount;
        valuesDecoderContext.setNonNullCount(nonNullCount);
        valuesDecoderContext.setValueCount(valueCount);
    }
    if (batchNonNullCount == 0) {
        Block block = RunLengthEncodedBlock.create(field.getType(), null, newBatchSize);
        return new ColumnChunk(block, definitionLevels, repetitionLevelDecodingContext.getRepetitionLevels());
    }
    int[] values = new int[newBatchSize];
    boolean[] isNull = new boolean[newBatchSize];
    int offset = 0;
    for (ValuesDecoderContext valuesDecoderContext : definitionLevelDecodingContext.getValuesDecoderContexts()) {
        ((Int32ValuesDecoder) valuesDecoderContext.getValuesDecoder()).readNext(values, offset, valuesDecoderContext.getNonNullCount());
        int valueDestinationIndex = offset + valuesDecoderContext.getValueCount() - 1;
        int valueSourceIndex = offset + valuesDecoderContext.getNonNullCount() - 1;
        int definitionLevelIndex = valuesDecoderContext.getEnd() - 1;
        while (valueDestinationIndex >= offset) {
            if (definitionLevels[definitionLevelIndex] == maxDefinitionLevel) {
                values[valueDestinationIndex--] = values[valueSourceIndex--];
            } else if (definitionLevels[definitionLevelIndex] == maxDefinitionLevel - 1) {
                values[valueDestinationIndex] = 0;
                isNull[valueDestinationIndex] = true;
                valueDestinationIndex--;
            }
            definitionLevelIndex--;
        }
        offset += valuesDecoderContext.getValueCount();
    }
    boolean hasNoNull = batchNonNullCount == newBatchSize;
    Block block = new IntArrayBlock(newBatchSize, hasNoNull ? Optional.empty() : Optional.of(isNull), values);
    return new ColumnChunk(block, definitionLevels, repetitionLevelDecodingContext.getRepetitionLevels());
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Int32ValuesDecoder(com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Block(com.facebook.presto.common.block.Block) ColumnChunk(com.facebook.presto.parquet.reader.ColumnChunk)

Example 2 with Int32ValuesDecoder

use of com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder in project presto by prestodb.

the class Int32NestedBatchReader method seek.

@Override
protected void seek() throws IOException {
    if (readOffset == 0) {
        return;
    }
    int maxDefinitionLevel = columnDescriptor.getMaxDefinitionLevel();
    RepetitionLevelDecodingContext repetitionLevelDecodingContext = readRepetitionLevels(readOffset);
    DefinitionLevelDecodingContext definitionLevelDecodingContext = readDefinitionLevels(repetitionLevelDecodingContext.getDLValuesDecoderContexts(), repetitionLevelDecodingContext.getRepetitionLevels().length);
    int[] definitionLevels = definitionLevelDecodingContext.getDefinitionLevels();
    for (ValuesDecoderContext valuesDecoderContext : definitionLevelDecodingContext.getValuesDecoderContexts()) {
        int valueCount = 0;
        for (int i = valuesDecoderContext.getStart(); i < valuesDecoderContext.getEnd(); i++) {
            valueCount += (definitionLevels[i] == maxDefinitionLevel ? 1 : 0);
        }
        Int32ValuesDecoder intValuesDecoder = (Int32ValuesDecoder) valuesDecoderContext.getValuesDecoder();
        intValuesDecoder.skip(valueCount);
    }
}
Also used : Int32ValuesDecoder(com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder)

Example 3 with Int32ValuesDecoder

use of com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder in project presto by prestodb.

the class Int32NestedBatchReader method readNestedNoNull.

@Override
protected ColumnChunk readNestedNoNull() throws IOException {
    int maxDefinitionLevel = columnDescriptor.getMaxDefinitionLevel();
    RepetitionLevelDecodingContext repetitionLevelDecodingContext = readRepetitionLevels(nextBatchSize);
    DefinitionLevelDecodingContext definitionLevelDecodingContext = readDefinitionLevels(repetitionLevelDecodingContext.getDLValuesDecoderContexts(), repetitionLevelDecodingContext.getRepetitionLevels().length);
    int[] definitionLevels = definitionLevelDecodingContext.getDefinitionLevels();
    int newBatchSize = 0;
    for (ValuesDecoderContext valuesDecoderContext : definitionLevelDecodingContext.getValuesDecoderContexts()) {
        int valueCount = 0;
        for (int i = valuesDecoderContext.getStart(); i < valuesDecoderContext.getEnd(); i++) {
            valueCount += (definitionLevels[i] == maxDefinitionLevel ? 1 : 0);
        }
        newBatchSize += valueCount;
        valuesDecoderContext.setNonNullCount(valueCount);
        valuesDecoderContext.setValueCount(valueCount);
    }
    int[] values = new int[newBatchSize];
    int offset = 0;
    for (ValuesDecoderContext valuesDecoderContext : definitionLevelDecodingContext.getValuesDecoderContexts()) {
        ((Int32ValuesDecoder) valuesDecoderContext.getValuesDecoder()).readNext(values, offset, valuesDecoderContext.getNonNullCount());
        offset += valuesDecoderContext.getValueCount();
    }
    Block block = new IntArrayBlock(newBatchSize, Optional.empty(), values);
    return new ColumnChunk(block, definitionLevels, repetitionLevelDecodingContext.getRepetitionLevels());
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Int32ValuesDecoder(com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Block(com.facebook.presto.common.block.Block) ColumnChunk(com.facebook.presto.parquet.reader.ColumnChunk)

Aggregations

Int32ValuesDecoder (com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder)3 Block (com.facebook.presto.common.block.Block)2 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)2 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)2 ColumnChunk (com.facebook.presto.parquet.reader.ColumnChunk)2