Search in sources :

Example 31 with RunLengthEncodedBlock

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

the class AbstractDecimalSelectiveStreamReader method getBlock.

@Override
public Block getBlock(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 new RunLengthEncodedBlock(nullBlock, positionCount);
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount == outputPositionCount) {
        Block block = makeBlock(positionCount, nullsAllowed, nulls, values);
        nulls = null;
        values = null;
        return block;
    }
    long[] valuesCopy = new long[valuesPerPosition * positionCount];
    boolean[] nullsCopy = null;
    if (includeNulls) {
        nullsCopy = new boolean[positionCount];
    }
    copyValues(positions, positionCount, valuesCopy, nullsCopy);
    return makeBlock(positionCount, includeNulls, nullsCopy, valuesCopy);
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 32 with RunLengthEncodedBlock

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

the class BooleanSelectiveStreamReader 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 ByteArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
Also used : ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 33 with RunLengthEncodedBlock

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

the class BooleanSelectiveStreamReader method getBlock.

@Override
public Block getBlock(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 new RunLengthEncodedBlock(NULL_BLOCK, positionCount);
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount == outputPositionCount) {
        Block block = new ByteArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
        nulls = null;
        values = null;
        return block;
    }
    byte[] valuesCopy = new byte[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] = this.values[i];
        if (nullsCopy != null) {
            nullsCopy[positionIndex] = this.nulls[i];
        }
        positionIndex++;
        if (positionIndex >= positionCount) {
            break;
        }
        nextPosition = positions[positionIndex];
    }
    return new ByteArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) Block(com.facebook.presto.common.block.Block) ByteArrayBlock(com.facebook.presto.common.block.ByteArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 34 with RunLengthEncodedBlock

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

the class TestColumnarArray method assertRunLengthEncodedBlock.

private static <T> void assertRunLengthEncodedBlock(Block block, T[] expectedValues) {
    for (int position = 0; position < block.getPositionCount(); position++) {
        RunLengthEncodedBlock runLengthEncodedBlock = createTestRleBlock(block, position);
        T[] expectedDictionaryValues = createTestRleExpectedValues(expectedValues, position);
        assertBlock(runLengthEncodedBlock, expectedDictionaryValues);
        assertColumnarArray(runLengthEncodedBlock, expectedDictionaryValues);
    }
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 35 with RunLengthEncodedBlock

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

the class TestColumnarRow method assertRunLengthEncodedBlock.

private static <T> void assertRunLengthEncodedBlock(Block block, T[] expectedValues) {
    for (int position = 0; position < block.getPositionCount(); position++) {
        RunLengthEncodedBlock runLengthEncodedBlock = createTestRleBlock(block, position);
        T[] expectedDictionaryValues = createTestRleExpectedValues(expectedValues, position);
        assertBlock(runLengthEncodedBlock, expectedDictionaryValues);
        assertColumnarRow(runLengthEncodedBlock, expectedDictionaryValues);
    }
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Aggregations

RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)50 Block (com.facebook.presto.common.block.Block)27 Page (com.facebook.presto.common.Page)14 Test (org.testng.annotations.Test)9 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)7 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)6 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)6 PrestoException (com.facebook.presto.spi.PrestoException)6 ByteArrayBlock (com.facebook.presto.common.block.ByteArrayBlock)5 Slice (io.airlift.slice.Slice)5 IOException (java.io.IOException)4 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)3 LazyBlock (com.facebook.presto.common.block.LazyBlock)3 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)3 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)2 BlockLease (com.facebook.presto.common.block.BlockLease)2 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)2 VariableWidthBlock (com.facebook.presto.common.block.VariableWidthBlock)2 Type (com.facebook.presto.common.type.Type)2 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)2