Search in sources :

Example 21 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.

the class TestPageProcessorCompiler method testSanityRLE.

@Test
public void testSanityRLE() {
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), MAX_BATCH_SIZE).get();
    Slice varcharValue = Slices.utf8Slice("hello");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
    RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
    assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 22 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.

the class UnionColumnReader method getBlocks.

private Block[] getBlocks(int positionCount) throws IOException {
    if (dataStream == null) {
        throw new OrcCorruptionException(column.getOrcDataSourceId(), "Value is not null but data stream is missing");
    }
    Block[] blocks = new Block[fieldReaders.size() + 1];
    byte[] tags = dataStream.next(positionCount);
    blocks[0] = new ByteArrayBlock(positionCount, Optional.empty(), tags);
    boolean[][] valueIsNonNull = new boolean[fieldReaders.size()][positionCount];
    int[] nonNullValueCount = new int[fieldReaders.size()];
    for (int i = 0; i < positionCount; i++) {
        valueIsNonNull[tags[i]][i] = true;
        nonNullValueCount[tags[i]]++;
    }
    for (int i = 0; i < fieldReaders.size(); i++) {
        Type fieldType = type.getTypeParameters().get(i + 1);
        if (nonNullValueCount[i] > 0) {
            ColumnReader reader = fieldReaders.get(i);
            reader.prepareNextRead(nonNullValueCount[i]);
            Block rawBlock = blockFactory.createBlock(nonNullValueCount[i], reader::readBlock, true);
            blocks[i + 1] = new LazyBlock(positionCount, new UnpackLazyBlockLoader(rawBlock, fieldType, valueIsNonNull[i]));
        } else {
            blocks[i + 1] = new RunLengthEncodedBlock(fieldType.createBlockBuilder(null, 1).appendNull().build(), positionCount);
        }
    }
    return blocks;
}
Also used : Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ReaderUtils.verifyStreamType(io.trino.orc.reader.ReaderUtils.verifyStreamType) LazyBlock(io.trino.spi.block.LazyBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RowBlock(io.trino.spi.block.RowBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) OrcCorruptionException(io.trino.orc.OrcCorruptionException) ColumnReaders.createColumnReader(io.trino.orc.reader.ColumnReaders.createColumnReader) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 23 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.

the class BigintGroupByHash method addPage.

@Override
public Work<?> addPage(Page page) {
    currentPageSizeInBytes = page.getRetainedSizeInBytes();
    Block block = page.getBlock(hashChannel);
    if (block instanceof RunLengthEncodedBlock) {
        return new AddRunLengthEncodedPageWork((RunLengthEncodedBlock) block);
    }
    if (block instanceof DictionaryBlock) {
        return new AddDictionaryPageWork((DictionaryBlock) block);
    }
    return new AddPageWork(block);
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 24 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.

the class BigintGroupByHash method getGroupIds.

@Override
public Work<GroupByIdBlock> getGroupIds(Page page) {
    currentPageSizeInBytes = page.getRetainedSizeInBytes();
    Block block = page.getBlock(hashChannel);
    if (block instanceof RunLengthEncodedBlock) {
        return new GetRunLengthEncodedGroupIdsWork((RunLengthEncodedBlock) block);
    }
    if (block instanceof DictionaryBlock) {
        return new GetDictionaryGroupIdsWork((DictionaryBlock) block);
    }
    return new GetGroupIdsWork(page.getBlock(hashChannel));
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 25 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.

the class GroupIdOperator method generateNextPage.

private Page generateNextPage() {
    // generate 'n' pages for every input page, where n is the number of grouping sets
    Block[] outputBlocks = new Block[types.size()];
    for (int i = 0; i < groupingSetInputs[currentGroupingSet].length; i++) {
        if (groupingSetInputs[currentGroupingSet][i] == -1) {
            outputBlocks[i] = new RunLengthEncodedBlock(nullBlocks[i], currentPage.getPositionCount());
        } else {
            outputBlocks[i] = currentPage.getBlock(groupingSetInputs[currentGroupingSet][i]);
        }
    }
    outputBlocks[outputBlocks.length - 1] = new RunLengthEncodedBlock(groupIdBlocks[currentGroupingSet], currentPage.getPositionCount());
    currentGroupingSet = (currentGroupingSet + 1) % groupingSetInputs.length;
    Page outputPage = new Page(currentPage.getPositionCount(), outputBlocks);
    if (currentGroupingSet == 0) {
        currentPage = null;
    }
    return outputPage;
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Aggregations

RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)41 Block (io.trino.spi.block.Block)25 Page (io.trino.spi.Page)22 Test (org.testng.annotations.Test)13 DictionaryBlock (io.trino.spi.block.DictionaryBlock)8 TrinoException (io.trino.spi.TrinoException)6 BlockBuilder (io.trino.spi.block.BlockBuilder)6 Slice (io.airlift.slice.Slice)5 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)5 LongArrayBlock (io.trino.spi.block.LongArrayBlock)5 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)4 LazyBlock (io.trino.spi.block.LazyBlock)4 Type (io.trino.spi.type.Type)4 IOException (java.io.IOException)4 Utils.nativeValueToBlock (io.trino.spi.predicate.Utils.nativeValueToBlock)3 UncheckedIOException (java.io.UncheckedIOException)3 BlockAssertions.createStringSequenceBlock (io.trino.block.BlockAssertions.createStringSequenceBlock)2 PageSplitterUtil.splitPage (io.trino.execution.buffer.PageSplitterUtil.splitPage)2 DriverYieldSignal (io.trino.operator.DriverYieldSignal)2 PageProcessor (io.trino.operator.project.PageProcessor)2