Search in sources :

Example 36 with RunLengthEncodedBlock

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

the class AggregationTestUtils method maskPagesWithRle.

// Adds the mask as the last channel
private static Page[] maskPagesWithRle(boolean maskValue, Page... pages) {
    Page[] maskedPages = new Page[pages.length];
    for (int i = 0; i < pages.length; i++) {
        Page page = pages[i];
        maskedPages[i] = page.appendColumn(new RunLengthEncodedBlock(BooleanType.createBlockForSingleNonNullValue(maskValue), page.getPositionCount()));
    }
    return maskedPages;
}
Also used : Page(com.facebook.presto.common.Page) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 37 with RunLengthEncodedBlock

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

the class TestApproximatePercentileAggregation method createRLEBlock.

private static RunLengthEncodedBlock createRLEBlock(double percentile, int positionCount) {
    BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1);
    DOUBLE.writeDouble(blockBuilder, percentile);
    return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 38 with RunLengthEncodedBlock

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

the class SliceDirectSelectiveStreamReader 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(outputType.createBlockBuilder(null, 1).appendNull().build(), positionCount));
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount != outputPositionCount) {
        compactValues(positions, positionCount, includeNulls);
    }
    return newLease(new VariableWidthBlock(positionCount, dataAsSlice, offsets, Optional.ofNullable(includeNulls ? nulls : null)));
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock)

Example 39 with RunLengthEncodedBlock

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

the class SliceDirectSelectiveStreamReader 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(outputType.createBlockBuilder(null, 1).appendNull().build(), positionCount);
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount != outputPositionCount) {
        compactValues(positions, positionCount, includeNulls);
    }
    Block block = new VariableWidthBlock(positionCount, dataAsSlice, offsets, Optional.ofNullable(includeNulls ? nulls : null));
    dataAsSlice = null;
    data = null;
    offsets = null;
    nulls = null;
    return block;
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock)

Example 40 with RunLengthEncodedBlock

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

the class TimestampSelectiveStreamReader 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 LongArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
        nulls = null;
        values = null;
        return block;
    }
    long[] valuesCopy = new long[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 LongArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) Block(com.facebook.presto.common.block.Block) 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