Search in sources :

Example 6 with RunLengthEncodedBlock

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

the class TestGroupByHash method testRunLengthEncodedBigintGroupByHash.

@Test
public void testRunLengthEncodedBigintGroupByHash() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    Block block = BlockAssertions.createLongsBlock(0L);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
    Page page = new Page(new RunLengthEncodedBlock(block, 2), new RunLengthEncodedBlock(hashBlock, 2));
    groupByHash.addPage(page).process();
    assertEquals(groupByHash.getGroupCount(), 1);
    Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
    work.process();
    GroupByIdBlock groupIds = work.getResult();
    assertEquals(groupIds.getGroupCount(), 1);
    assertEquals(groupIds.getPositionCount(), 2);
    assertEquals(groupIds.getGroupId(0), 0);
    assertEquals(groupIds.getGroupId(1), 0);
    List<Block> children = groupIds.getChildren();
    assertEquals(children.size(), 1);
    assertTrue(children.get(0) instanceof RunLengthEncodedBlock);
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 7 with RunLengthEncodedBlock

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

the class TestPageProcessorCompiler method testSanityFilterOnRLE.

@Test
public void testSanityFilterOnRLE() {
    ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get();
    Page page = new Page(createRLEBlock(5L, 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);
    RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) ResolvedFunction(io.trino.metadata.ResolvedFunction) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 8 with RunLengthEncodedBlock

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

the class TestOrcDeletedRows method createTestPage.

private Page createTestPage(int originalTransactionStart, int originalTransactionEnd) {
    int size = originalTransactionEnd - originalTransactionStart;
    BlockBuilder originalTransaction = BIGINT.createFixedSizeBlockBuilder(size);
    for (long i = originalTransactionStart; i < originalTransactionEnd; i++) {
        originalTransaction.writeLong(i);
    }
    return new Page(size, originalTransaction.build(), new RunLengthEncodedBlock(bucketBlock, size), new RunLengthEncodedBlock(rowIdBlock, size));
}
Also used : Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 9 with RunLengthEncodedBlock

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

the class TestPageSplitterUtil method testSplitPageNonDecreasingPageSize.

@Test
public void testSplitPageNonDecreasingPageSize() {
    int positionCount = 100;
    int maxPageSizeInBytes = 1;
    List<Type> types = ImmutableList.of(VARCHAR);
    Slice expectedValue = wrappedBuffer("test".getBytes(UTF_8));
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 1, expectedValue.length());
    blockBuilder.writeBytes(expectedValue, 0, expectedValue.length()).closeEntry();
    Block rleBlock = new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
    Page initialPage = new Page(rleBlock);
    List<Page> pages = splitPage(initialPage, maxPageSizeInBytes);
    // the page should only be split in half as the recursion should terminate
    // after seeing that the size of the Page doesn't decrease
    assertEquals(pages.size(), 2);
    Page first = pages.get(0);
    Page second = pages.get(1);
    // the size of the pages will remain the same and should be greater than the maxPageSizeInBytes
    assertGreaterThan((int) first.getSizeInBytes(), maxPageSizeInBytes);
    assertGreaterThan((int) second.getSizeInBytes(), maxPageSizeInBytes);
    assertPositionCount(pages, positionCount);
    MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
    MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(initialPage));
    assertEquals(actual, expected);
}
Also used : Type(io.trino.spi.type.Type) Slice(io.airlift.slice.Slice) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) PageSplitterUtil.splitPage(io.trino.execution.buffer.PageSplitterUtil.splitPage) SequencePageBuilder.createSequencePage(io.trino.SequencePageBuilder.createSequencePage) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 10 with RunLengthEncodedBlock

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

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.trino.spi.type.Type) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) 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