Search in sources :

Example 41 with RunLengthEncodedBlock

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

the class TestMarkDistinctOperator method testRleDistinctMask.

@Test(dataProvider = "hashEnabledValues")
public void testRleDistinctMask(boolean hashEnabled) {
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT);
    List<Page> inputs = rowPagesBuilder.addSequencePage(100, 0).addSequencePage(100, 50).addSequencePage(1, 200).addSequencePage(1, 100).build();
    Page firstInput = inputs.get(0);
    Page secondInput = inputs.get(1);
    Page singleDistinctPage = inputs.get(2);
    Page singleNotDistinctPage = inputs.get(3);
    OperatorFactory operatorFactory = new MarkDistinctOperatorFactory(0, new PlanNodeId("test"), rowPagesBuilder.getTypes(), ImmutableList.of(0), rowPagesBuilder.getHashChannel(), joinCompiler, blockTypeOperators);
    // mask channel is appended to the input
    int maskChannel = firstInput.getChannelCount();
    try (Operator operator = operatorFactory.createOperator(driverContext)) {
        operator.addInput(firstInput);
        Block allDistinctOutput = operator.getOutput().getBlock(maskChannel);
        operator.addInput(firstInput);
        Block noDistinctOutput = operator.getOutput().getBlock(maskChannel);
        // all distinct and no distinct conditions produce RLE blocks
        assertInstanceOf(allDistinctOutput, RunLengthEncodedBlock.class);
        assertTrue(BOOLEAN.getBoolean(allDistinctOutput, 0));
        assertInstanceOf(noDistinctOutput, RunLengthEncodedBlock.class);
        assertFalse(BOOLEAN.getBoolean(noDistinctOutput, 0));
        operator.addInput(secondInput);
        Block halfDistinctOutput = operator.getOutput().getBlock(maskChannel);
        // [0,50) is not distinct
        for (int position = 0; position < 50; position++) {
            assertFalse(BOOLEAN.getBoolean(halfDistinctOutput, position));
        }
        for (int position = 50; position < 100; position++) {
            assertTrue(BOOLEAN.getBoolean(halfDistinctOutput, position));
        }
        operator.addInput(singleDistinctPage);
        Block singleDistinctBlock = operator.getOutput().getBlock(maskChannel);
        assertFalse(singleDistinctBlock instanceof RunLengthEncodedBlock, "single position inputs should not be RLE");
        assertTrue(BOOLEAN.getBoolean(singleDistinctBlock, 0));
        operator.addInput(singleNotDistinctPage);
        Block singleNotDistinctBlock = operator.getOutput().getBlock(maskChannel);
        assertFalse(singleNotDistinctBlock instanceof RunLengthEncodedBlock, "single position inputs should not be RLE");
        assertFalse(BOOLEAN.getBoolean(singleNotDistinctBlock, 0));
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) MarkDistinctOperatorFactory(io.trino.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) RowPagesBuilder(io.trino.RowPagesBuilder) MarkDistinctOperatorFactory(io.trino.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

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