Search in sources :

Example 41 with RunLengthEncodedBlock

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

the class DoubleSelectiveStreamReader 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)

Example 42 with RunLengthEncodedBlock

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

the class FloatSelectiveStreamReader 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 IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
        nulls = null;
        values = 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] = this.values[i];
        if (nullsCopy != null) {
            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) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 43 with RunLengthEncodedBlock

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

the class ListSelectiveStreamReader 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);
    }
    BlockLease elementBlockLease;
    if (elementOutputPositionCount == 0) {
        elementBlockLease = newLease(outputType.getElementType().createBlockBuilder(null, 0).build());
    } else {
        elementBlockLease = elementStreamReader.getBlockView(elementOutputPositions, elementOutputPositionCount);
    }
    valuesInUse = true;
    Block block = ArrayBlock.fromElementBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), offsets, elementBlockLease.get());
    return newLease(block, () -> closeBlockLease(elementBlockLease));
}
Also used : BlockLease(com.facebook.presto.common.block.BlockLease) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) ArrayBlock(com.facebook.presto.common.block.ArrayBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 44 with RunLengthEncodedBlock

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

the class ByteSelectiveStreamReader 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 45 with RunLengthEncodedBlock

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

the class DeltaPageSource method getNextPage.

@Override
public Page getNextPage() {
    try {
        Page dataPage = dataPageSource.getNextPage();
        if (dataPage == null) {
            // reader is done
            return null;
        }
        int positionCount = dataPage.getPositionCount();
        int dataColumnIndex = 0;
        int columnIndex = 0;
        Block[] blocksWithPartitionColumns = new Block[columnHandles.size()];
        for (DeltaColumnHandle columnHandle : columnHandles) {
            if (columnHandle.getColumnType() == PARTITION) {
                Block partitionValue = partitionValues.get(columnHandle.getName());
                blocksWithPartitionColumns[columnIndex++] = new RunLengthEncodedBlock(partitionValue, positionCount);
            } else {
                blocksWithPartitionColumns[columnIndex++] = dataPage.getBlock(dataColumnIndex);
                dataColumnIndex++;
            }
        }
        return new Page(positionCount, blocksWithPartitionColumns);
    } catch (PrestoException exception) {
        closeWithSuppression(exception);
        // already properly handled exception - throw without any additional info
        throw exception;
    } catch (RuntimeException exception) {
        closeWithSuppression(exception);
        throw new PrestoException(DELTA_READ_DATA_ERROR, exception);
    }
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) PrestoException(com.facebook.presto.spi.PrestoException) 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