Search in sources :

Example 26 with DictionaryBlock

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

the class TestUnnestBlockBuilder method testAppendRange.

private static void testAppendRange(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
    unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
    assertTrue(values.length >= 3, "test requires at least 3 elements in values");
    int startIndex = 1;
    int length = values.length - 2;
    unnestBlockBuilder.appendRange(startIndex, length);
    Block block = unnestBlockBuilder.buildOutputAndFlush();
    assertTrue(block instanceof DictionaryBlock);
    assertBlock(block, Arrays.copyOfRange(values, startIndex, startIndex + length));
}
Also used : PageBuilderStatus(io.trino.spi.block.PageBuilderStatus) DictionaryBlock(io.trino.spi.block.DictionaryBlock) TestingUnnesterUtil.createSimpleBlock(io.trino.operator.unnest.TestingUnnesterUtil.createSimpleBlock) ColumnarTestUtils.assertBlock(io.trino.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block)

Example 27 with DictionaryBlock

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

the class TestUnnestBlockBuilder method testAppendSingleElement.

private static void testAppendSingleElement(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
    // Test unnestBlockBuilder output over the course of building output
    for (int testCount = 1; testCount <= values.length; testCount++) {
        unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
        for (int i = 0; i < testCount; i++) {
            unnestBlockBuilder.appendElement(i);
        }
        Block block = unnestBlockBuilder.buildOutputAndFlush();
        assertTrue(block instanceof DictionaryBlock);
        assertBlock(block, Arrays.copyOf(values, testCount));
    }
}
Also used : PageBuilderStatus(io.trino.spi.block.PageBuilderStatus) DictionaryBlock(io.trino.spi.block.DictionaryBlock) TestingUnnesterUtil.createSimpleBlock(io.trino.operator.unnest.TestingUnnesterUtil.createSimpleBlock) ColumnarTestUtils.assertBlock(io.trino.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block)

Example 28 with DictionaryBlock

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

the class TestUnnestBlockBuilder method testAppendNull.

private static void testAppendNull(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
    assertTrue(values.length >= 1, "values should have at least one element");
    int nullIndex = -1;
    for (int i = 0; i < values.length; i++) {
        if (values[i] == null) {
            nullIndex = i;
            break;
        }
    }
    // Test-1: appending a non-null element
    unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
    unnestBlockBuilder.appendElement(0);
    Block block = unnestBlockBuilder.buildOutputAndFlush();
    assertTrue(block instanceof DictionaryBlock);
    assertBlock(block, new Slice[] { values[0] });
    // Test-2: appending a non-null element and a null.
    unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
    unnestBlockBuilder.appendElement(0);
    unnestBlockBuilder.appendNull();
    block = unnestBlockBuilder.buildOutputAndFlush();
    assertTrue((block instanceof DictionaryBlock) || (nullIndex == -1));
    assertFalse((block instanceof DictionaryBlock) && (nullIndex == -1));
    assertBlock(block, new Slice[] { values[0], null });
    // Test-3: appending a non-null element, a null, and another non-null element.
    unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
    unnestBlockBuilder.appendElement(0);
    unnestBlockBuilder.appendNull();
    unnestBlockBuilder.appendElement(0);
    block = unnestBlockBuilder.buildOutputAndFlush();
    assertTrue((block instanceof DictionaryBlock) || (nullIndex == -1));
    assertFalse((block instanceof DictionaryBlock) && (nullIndex == -1));
    assertBlock(block, new Slice[] { values[0], null, values[0] });
}
Also used : PageBuilderStatus(io.trino.spi.block.PageBuilderStatus) DictionaryBlock(io.trino.spi.block.DictionaryBlock) TestingUnnesterUtil.createSimpleBlock(io.trino.operator.unnest.TestingUnnesterUtil.createSimpleBlock) ColumnarTestUtils.assertBlock(io.trino.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block)

Example 29 with DictionaryBlock

use of io.trino.spi.block.DictionaryBlock 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 30 with DictionaryBlock

use of io.trino.spi.block.DictionaryBlock 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)

Aggregations

DictionaryBlock (io.trino.spi.block.DictionaryBlock)71 Block (io.trino.spi.block.Block)39 Test (org.testng.annotations.Test)38 Slice (io.airlift.slice.Slice)21 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)16 Page (io.trino.spi.Page)15 LazyBlock (io.trino.spi.block.LazyBlock)10 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)9 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)9 LongArrayBlock (io.trino.spi.block.LongArrayBlock)9 ColumnarTestUtils.assertBlock (io.trino.block.ColumnarTestUtils.assertBlock)8 PageBuilderStatus (io.trino.spi.block.PageBuilderStatus)8 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)7 DictionaryId (io.trino.spi.block.DictionaryId)6 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)5 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)5 TestingUnnesterUtil.createSimpleBlock (io.trino.operator.unnest.TestingUnnesterUtil.createSimpleBlock)5 BlockBuilder (io.trino.spi.block.BlockBuilder)5 DictionaryId.randomDictionaryId (io.trino.spi.block.DictionaryId.randomDictionaryId)5 IntArrayBlock (io.trino.spi.block.IntArrayBlock)5