Search in sources :

Example 1 with BlockAssertions.createStringSequenceBlock

use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.

the class TestGroupByHash method testAppendTo.

@Test
public void testAppendTo() {
    Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    Work<GroupByIdBlock> work = groupByHash.getGroupIds(new Page(valuesBlock, hashBlock));
    work.process();
    GroupByIdBlock groupIds = work.getResult();
    for (int i = 0; i < groupIds.getPositionCount(); i++) {
        assertEquals(groupIds.getGroupId(i), i);
    }
    assertEquals(groupByHash.getGroupCount(), 100);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page page = pageBuilder.build();
    // Ensure that all blocks have the same positionCount
    for (int i = 0; i < groupByHash.getTypes().size(); i++) {
        assertEquals(page.getBlock(i).getPositionCount(), 100);
    }
    assertEquals(page.getPositionCount(), 100);
    BlockAssertions.assertBlockEquals(VARCHAR, page.getBlock(0), valuesBlock);
    BlockAssertions.assertBlockEquals(BIGINT, page.getBlock(1), hashBlock);
}
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) PageBuilder(io.trino.spi.PageBuilder) Test(org.testng.annotations.Test)

Example 2 with BlockAssertions.createStringSequenceBlock

use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.

the class TestGroupByHash method testForceRehash.

@Test
public void testForceRehash() {
    // Create a page with positionCount >> expected size of groupByHash
    Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
    // Create group by hash with extremely small size
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 4, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    // Ensure that all groups are present in group by hash
    for (int i = 0; i < valuesBlock.getPositionCount(); i++) {
        assertTrue(groupByHash.contains(i, new Page(valuesBlock, hashBlock), CONTAINS_CHANNELS));
    }
}
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) Test(org.testng.annotations.Test)

Example 3 with BlockAssertions.createStringSequenceBlock

use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.

the class TestGroupByHash method testContainsMultipleColumns.

@Test
public void testContainsMultipleColumns() {
    Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
    Block stringValuesBlock = BlockAssertions.createStringSequenceBlock(0, 10);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), valuesBlock, stringValuesBlock);
    int[] hashChannels = { 0, 1 };
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE, VARCHAR), hashChannels, Optional.of(2), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    groupByHash.getGroupIds(new Page(valuesBlock, stringValuesBlock, hashBlock)).process();
    Block testValuesBlock = BlockAssertions.createDoublesBlock((double) 3);
    Block testStringValuesBlock = BlockAssertions.createStringsBlock("3");
    Block testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), testValuesBlock, testStringValuesBlock);
    assertTrue(groupByHash.contains(0, new Page(testValuesBlock, testStringValuesBlock, testHashBlock), hashChannels));
}
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) Test(org.testng.annotations.Test)

Aggregations

BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)3 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)3 BlockAssertions.createStringSequenceBlock (io.trino.block.BlockAssertions.createStringSequenceBlock)3 GroupByHash.createGroupByHash (io.trino.operator.GroupByHash.createGroupByHash)3 Page (io.trino.spi.Page)3 Block (io.trino.spi.block.Block)3 DictionaryBlock (io.trino.spi.block.DictionaryBlock)3 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)3 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)3 TypeTestUtils.getHashBlock (io.trino.type.TypeTestUtils.getHashBlock)3 Test (org.testng.annotations.Test)3 PageBuilder (io.trino.spi.PageBuilder)1