Search in sources :

Example 1 with IntArrayBlock

use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.

the class Int32FlatBatchReader method readWithNull.

private ColumnChunk readWithNull() throws IOException {
    int[] values = new int[nextBatchSize];
    boolean[] isNull = new boolean[nextBatchSize];
    int totalNonNullCount = 0;
    int remainingInBatch = nextBatchSize;
    int startOffset = 0;
    while (remainingInBatch > 0) {
        if (remainingCountInPage == 0) {
            if (!readNextPage()) {
                break;
            }
        }
        int chunkSize = Math.min(remainingCountInPage, remainingInBatch);
        int nonNullCount = definitionLevelDecoder.readNext(isNull, startOffset, chunkSize);
        totalNonNullCount += nonNullCount;
        if (nonNullCount > 0) {
            valuesDecoder.readNext(values, startOffset, nonNullCount);
            int valueDestinationIndex = startOffset + chunkSize - 1;
            int valueSourceIndex = startOffset + nonNullCount - 1;
            while (valueDestinationIndex >= startOffset) {
                if (!isNull[valueDestinationIndex]) {
                    values[valueDestinationIndex] = values[valueSourceIndex];
                    valueSourceIndex--;
                }
                valueDestinationIndex--;
            }
        }
        startOffset += chunkSize;
        remainingInBatch -= chunkSize;
        remainingCountInPage -= chunkSize;
    }
    if (remainingInBatch != 0) {
        throw new ParquetDecodingException("Still remaining to be read in current batch.");
    }
    if (totalNonNullCount == 0) {
        Block block = RunLengthEncodedBlock.create(field.getType(), null, nextBatchSize);
        return new ColumnChunk(block, new int[0], new int[0]);
    }
    boolean hasNoNull = totalNonNullCount == nextBatchSize;
    Block block = new IntArrayBlock(nextBatchSize, hasNoNull ? Optional.empty() : Optional.of(isNull), values);
    return new ColumnChunk(block, new int[0], new int[0]);
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) ParquetDecodingException(org.apache.parquet.io.ParquetDecodingException) 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 IntArrayBlock

use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.

the class Int32FlatBatchReader method readWithoutNull.

private ColumnChunk readWithoutNull() throws IOException {
    int[] values = new int[nextBatchSize];
    int remainingInBatch = nextBatchSize;
    int startOffset = 0;
    while (remainingInBatch > 0) {
        if (remainingCountInPage == 0) {
            if (!readNextPage()) {
                break;
            }
        }
        int chunkSize = Math.min(remainingCountInPage, remainingInBatch);
        valuesDecoder.readNext(values, startOffset, chunkSize);
        startOffset += chunkSize;
        remainingInBatch -= chunkSize;
        remainingCountInPage -= chunkSize;
    }
    if (remainingInBatch != 0) {
        throw new ParquetDecodingException(format("Corrupted Parquet file: extra %d values to be consumed when scanning current batch", remainingInBatch));
    }
    Block block = new IntArrayBlock(nextBatchSize, Optional.empty(), values);
    return new ColumnChunk(block, new int[0], new int[0]);
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) ParquetDecodingException(org.apache.parquet.io.ParquetDecodingException) 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 3 with IntArrayBlock

use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.

the class FloatSelectiveStreamReader method getBlockView.

@Override
public BlockLease getBlockView(int[] positions, int positionCount) {
    checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
    checkState(outputRequired, "This stream reader doesn't produce output");
    checkState(positionCount <= outputPositionCount, "Not enough values");
    checkState(!valuesInUse, "BlockLease hasn't been closed yet");
    if (allNulls) {
        return newLease(new RunLengthEncodedBlock(NULL_BLOCK, positionCount));
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount != outputPositionCount) {
        compactValues(positions, positionCount, includeNulls);
    }
    return newLease(new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 4 with IntArrayBlock

use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.

the class AbstractLongSelectiveStreamReader method getIntArrayBlock.

private Block getIntArrayBlock(int[] positions, int positionCount, boolean includeNulls) {
    if (intValuesPopulated && positionCount == outputPositionCount) {
        Block block = new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), intValues);
        intValues = null;
        nulls = null;
        return block;
    }
    int[] valuesCopy = new int[positionCount];
    boolean[] nullsCopy = null;
    if (includeNulls) {
        nullsCopy = new boolean[positionCount];
    }
    int positionIndex = 0;
    int nextPosition = positions[positionIndex];
    for (int i = 0; i < outputPositionCount; i++) {
        if (outputPositions[i] < nextPosition) {
            continue;
        }
        assert outputPositions[i] == nextPosition;
        valuesCopy[positionIndex] = toIntExact(this.values[i]);
        if (includeNulls) {
            nullsCopy[positionIndex] = this.nulls[i];
        }
        positionIndex++;
        if (positionIndex >= positionCount) {
            break;
        }
        nextPosition = positions[positionIndex];
    }
    return new IntArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) ShortArrayBlock(com.facebook.presto.common.block.ShortArrayBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Block(com.facebook.presto.common.block.Block)

Example 5 with IntArrayBlock

use of com.facebook.presto.common.block.IntArrayBlock in project presto by prestodb.

the class TestIntArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    int[] intArray = { 0, 0, 1, 2, 3, 4 };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(new IntArrayBlock(0, Optional.empty(), new int[0]));
    testCompactBlock(new IntArrayBlock(intArray.length, Optional.of(valueIsNull), intArray));
    testIncompactBlock(new IntArrayBlock(intArray.length - 1, Optional.of(valueIsNull), intArray));
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Test(org.testng.annotations.Test)

Aggregations

IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)10 Block (com.facebook.presto.common.block.Block)6 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)6 ColumnChunk (com.facebook.presto.parquet.reader.ColumnChunk)4 Test (org.testng.annotations.Test)3 Int32ValuesDecoder (com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder)2 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)2 RowExpression (com.facebook.presto.spi.relation.RowExpression)2 ParquetDecodingException (org.apache.parquet.io.ParquetDecodingException)2 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)1 ShortArrayBlock (com.facebook.presto.common.block.ShortArrayBlock)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)1 CallExpression (com.facebook.presto.spi.relation.CallExpression)1