Search in sources :

Example 31 with RunLengthEncodedBlock

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

the class BenchmarkGroupByHash method createBigintPages.

private static List<Page> createBigintPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled, boolean useMixedBlockTypes) {
    List<Type> types = Collections.nCopies(channelCount, BIGINT);
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    if (hashEnabled) {
        types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
    }
    PageBuilder pageBuilder = new PageBuilder(types);
    int pageCount = 0;
    for (int position = 0; position < positionCount; position++) {
        int rand = ThreadLocalRandom.current().nextInt(groupCount);
        pageBuilder.declarePosition();
        for (int numChannel = 0; numChannel < channelCount; numChannel++) {
            BIGINT.writeLong(pageBuilder.getBlockBuilder(numChannel), rand);
        }
        if (hashEnabled) {
            BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), AbstractLongType.hash(rand));
        }
        if (pageBuilder.isFull()) {
            Page page = pageBuilder.build();
            pageBuilder.reset();
            if (useMixedBlockTypes) {
                if (pageCount % 3 == 0) {
                    pages.add(page);
                } else if (pageCount % 3 == 1) {
                    // rle page
                    Block[] blocks = new Block[page.getChannelCount()];
                    for (int channel = 0; channel < blocks.length; ++channel) {
                        blocks[channel] = new RunLengthEncodedBlock(page.getBlock(channel).getSingleValueBlock(0), page.getPositionCount());
                    }
                    pages.add(new Page(blocks));
                } else {
                    // dictionary page
                    int[] positions = IntStream.range(0, page.getPositionCount()).toArray();
                    Block[] blocks = new Block[page.getChannelCount()];
                    for (int channel = 0; channel < page.getChannelCount(); ++channel) {
                        blocks[channel] = new DictionaryBlock(page.getBlock(channel), positions);
                    }
                    pages.add(new Page(blocks));
                }
            } else {
                pages.add(page);
            }
            pageCount++;
        }
    }
    pages.add(pageBuilder.build());
    return pages.build();
}
Also used : Type(io.trino.spi.type.Type) AbstractLongType(io.trino.spi.type.AbstractLongType) ImmutableList(com.google.common.collect.ImmutableList) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 32 with RunLengthEncodedBlock

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

the class RcFileFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    Block[] blocks = new Block[fileInputColumnIndexes.length];
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), dataPage.getPositionCount());
        } else {
            blocks[i] = dataPage.getBlock(inputColumnIndex);
        }
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        rcFileWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new TrinoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 33 with RunLengthEncodedBlock

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

the class DictionaryAwarePageFilter method filter.

@Override
public SelectedPositions filter(ConnectorSession session, Page page) {
    Block block = page.getBlock(0).getLoadedBlock();
    if (block instanceof RunLengthEncodedBlock) {
        Block value = ((RunLengthEncodedBlock) block).getValue();
        Optional<boolean[]> selectedPosition = processDictionary(session, value);
        // in that case we fallback and process again so the correct error message sent
        if (selectedPosition.isPresent()) {
            return SelectedPositions.positionsRange(0, selectedPosition.get()[0] ? page.getPositionCount() : 0);
        }
    }
    if (block instanceof DictionaryBlock) {
        DictionaryBlock dictionaryBlock = (DictionaryBlock) block;
        // Attempt to process the dictionary.  If dictionary is processing has not been considered effective, an empty response will be returned
        Optional<boolean[]> selectedDictionaryPositions = processDictionary(session, dictionaryBlock.getDictionary());
        // record the usage count regardless of dictionary processing choice, so we have stats for next time
        lastDictionaryUsageCount += page.getPositionCount();
        // if dictionary was processed, produce a dictionary block; otherwise do normal processing
        if (selectedDictionaryPositions.isPresent()) {
            return selectDictionaryPositions(dictionaryBlock, selectedDictionaryPositions.get());
        }
    }
    return filter.filter(session, new Page(block));
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 34 with RunLengthEncodedBlock

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

the class TestRunLengthEncodedBlock method assertRleBlock.

private void assertRleBlock(int positionCount) {
    Slice expectedValue = createExpectedValue(0);
    Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
    Slice[] expectedValues = new Slice[positionCount];
    for (int position = 0; position < positionCount; position++) {
        expectedValues[position] = expectedValue;
    }
    assertBlock(block, TestRunLengthEncodedBlock::createBlockBuilder, expectedValues);
}
Also used : Slice(io.airlift.slice.Slice) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 35 with RunLengthEncodedBlock

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

the class TestDictionaryAwarePageFilter method testRleBlock.

private static void testRleBlock(boolean filterRange) {
    DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(filterRange, LongArrayBlock.class);
    RunLengthEncodedBlock match = new RunLengthEncodedBlock(createLongSequenceBlock(4, 5), 100);
    testFilter(filter, match, filterRange);
    RunLengthEncodedBlock noMatch = new RunLengthEncodedBlock(createLongSequenceBlock(0, 1), 100);
    testFilter(filter, noMatch, filterRange);
}
Also used : 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