Search in sources :

Example 1 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class FloatSelectiveColumnReader 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");
    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;
        }
        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(io.prestosql.spi.block.IntArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 2 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class AbstractDecimalSelectiveColumnReader method getBlock.

@Override
public Block<T> 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");
    if (allNulls) {
        return new RunLengthEncodedBlock(nullBlock, outputPositionCount);
    }
    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(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 3 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class RcFileReader method readBlock.

public Block readBlock(int columnIndex) throws IOException {
    checkArgument(readColumns.containsKey(columnIndex), "Column %s is not being read", columnIndex);
    checkState(currentChunkRowCount > 0, "No more data");
    if (columnIndex >= columns.length) {
        Type type = readColumns.get(columnIndex);
        Block nullBlock = type.createBlockBuilder(null, 1, 0).appendNull().build();
        return new RunLengthEncodedBlock(nullBlock, currentChunkRowCount);
    }
    return columns[columnIndex].readBlock(rowGroupPosition, currentChunkRowCount);
}
Also used : Type(io.prestosql.spi.type.Type) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 4 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class RcFilePageSource method getNextPage.

@Override
public Page getNextPage() {
    try {
        // advance in the current batch
        pageId++;
        // if the batch has been consumed, read the next batch
        int currentPageSize = rcFileReader.advance();
        if (currentPageSize < 0) {
            close();
            return null;
        }
        Block[] blocks = new Block[hiveColumnIndexes.length];
        for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
            if (constantBlocks[fieldId] != null) {
                blocks[fieldId] = new RunLengthEncodedBlock(constantBlocks[fieldId], currentPageSize);
            } else {
                blocks[fieldId] = createBlock(currentPageSize, fieldId);
            }
        }
        Page page = new Page(currentPageSize, blocks);
        return page;
    } catch (PrestoException e) {
        closeWithSuppression(e);
        throw e;
    } catch (RcFileCorruptionException e) {
        closeWithSuppression(e);
        throw new PrestoException(HIVE_BAD_DATA, format("Corrupted RC file: %s", rcFileReader.getId()), e);
    } catch (IOException | RuntimeException e) {
        closeWithSuppression(e);
        throw new PrestoException(HIVE_CURSOR_ERROR, format("Failed to read RC file: %s", rcFileReader.getId()), e);
    }
}
Also used : RcFileCorruptionException(io.prestosql.rcfile.RcFileCorruptionException) LazyBlock(io.prestosql.spi.block.LazyBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 5 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class BlockAssertions method createRLEBlock.

public static RunLengthEncodedBlock createRLEBlock(double value, int positionCount) {
    BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1);
    DOUBLE.writeDouble(blockBuilder, value);
    return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
Also used : RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Aggregations

RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)30 Block (io.prestosql.spi.block.Block)18 Page (io.prestosql.spi.Page)10 Test (org.testng.annotations.Test)7 BlockBuilder (io.prestosql.spi.block.BlockBuilder)6 Slice (io.airlift.slice.Slice)5 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)4 PrestoException (io.prestosql.spi.PrestoException)3 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)3 LazyBlock (io.prestosql.spi.block.LazyBlock)3 IOException (java.io.IOException)3 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)2 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)2 PageProcessor (io.prestosql.operator.project.PageProcessor)2 RowBlock (io.prestosql.spi.block.RowBlock)2 RowBlockBuilder (io.prestosql.spi.block.RowBlockBuilder)2 Type (io.prestosql.spi.type.Type)2 UncheckedIOException (java.io.UncheckedIOException)2 SequencePageBuilder.createSequencePage (io.prestosql.SequencePageBuilder.createSequencePage)1 PageSplitterUtil.splitPage (io.prestosql.execution.buffer.PageSplitterUtil.splitPage)1