Search in sources :

Example 11 with RunLengthEncodedBlock

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

the class BlockAssertions method createRLEBlock.

public static RunLengthEncodedBlock createRLEBlock(long value, int positionCount) {
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1);
    BIGINT.writeLong(blockBuilder, value);
    return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockBuilder(io.trino.spi.block.BlockBuilder) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder)

Example 12 with RunLengthEncodedBlock

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

the class TestRunLengthEncodedBlock method testPositionsSizeInBytes.

@Test
public void testPositionsSizeInBytes() {
    Block valueBlock = createSingleValueBlock(createExpectedValue(10));
    Block rleBlock = new RunLengthEncodedBlock(valueBlock, 10);
    // Size in bytes is not fixed per position
    assertTrue(rleBlock.fixedSizeInBytesPerPosition().isEmpty());
    // Accepts specific position selection
    boolean[] positions = new boolean[rleBlock.getPositionCount()];
    positions[0] = true;
    positions[1] = true;
    assertEquals(rleBlock.getPositionsSizeInBytes(positions, 2), valueBlock.getSizeInBytes());
    // Accepts null positions array with count only
    assertEquals(rleBlock.getPositionsSizeInBytes(null, 2), valueBlock.getSizeInBytes());
    // Always reports the same size in bytes regardless of positions
    for (int positionCount = 0; positionCount < rleBlock.getPositionCount(); positionCount++) {
        assertEquals(rleBlock.getPositionsSizeInBytes(null, positionCount), valueBlock.getSizeInBytes());
    }
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 13 with RunLengthEncodedBlock

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

the class TestRunLengthEncodedBlock method testEstimatedDataSizeForStats.

@Test
public void testEstimatedDataSizeForStats() {
    int positionCount = 10;
    Slice expectedValue = createExpectedValue(5);
    Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
    for (int postition = 0; postition < positionCount; postition++) {
        assertEquals(block.getEstimatedDataSizeForStats(postition), expectedValue.length());
    }
}
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) Test(org.testng.annotations.Test)

Example 14 with RunLengthEncodedBlock

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

the class TestColumnarRow method assertRunLengthEncodedBlock.

private static <T> void assertRunLengthEncodedBlock(Block block, T[] expectedValues) {
    for (int position = 0; position < block.getPositionCount(); position++) {
        RunLengthEncodedBlock runLengthEncodedBlock = createTestRleBlock(block, position);
        T[] expectedDictionaryValues = createTestRleExpectedValues(expectedValues, position);
        assertBlock(runLengthEncodedBlock, expectedDictionaryValues);
        assertColumnarRow(runLengthEncodedBlock, expectedDictionaryValues);
    }
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 15 with RunLengthEncodedBlock

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

the class AggregationTestUtils method maskPagesWithRle.

// Adds the mask as the last channel
private static Page[] maskPagesWithRle(boolean maskValue, Page... pages) {
    Page[] maskedPages = new Page[pages.length];
    for (int i = 0; i < pages.length; i++) {
        Page page = pages[i];
        maskedPages[i] = page.appendColumn(new RunLengthEncodedBlock(BooleanType.createBlockForSingleNonNullValue(maskValue), page.getPositionCount()));
    }
    return maskedPages;
}
Also used : 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