Search in sources :

Example 1 with BlockAssertions.createLongSequenceBlock

use of io.prestosql.block.BlockAssertions.createLongSequenceBlock in project hetu-core by openlookeng.

the class TestGroupByHash method testAppendToMultipleTuplesPerGroup.

@Test
public void testAppendToMultipleTuplesPerGroup() {
    List<Long> values = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        values.add(i % 50);
    }
    Block valuesBlock = BlockAssertions.createLongsBlock(values);
    Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    assertEquals(groupByHash.getGroupCount(), 50);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page outputPage = pageBuilder.build();
    assertEquals(outputPage.getPositionCount(), 50);
    BlockAssertions.assertBlockEquals(BIGINT, outputPage.getBlock(0), BlockAssertions.createLongSequenceBlock(0, 50));
}
Also used : ArrayList(java.util.ArrayList) GroupByHash.createGroupByHash(io.prestosql.operator.GroupByHash.createGroupByHash) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) TypeUtils.getHashBlock(io.prestosql.type.TypeUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringSequenceBlock(io.prestosql.block.BlockAssertions.createStringSequenceBlock) Page(io.prestosql.spi.Page) PageBuilder(io.prestosql.spi.PageBuilder) Test(org.testng.annotations.Test)

Aggregations

BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)1 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createStringSequenceBlock (io.prestosql.block.BlockAssertions.createStringSequenceBlock)1 GroupByHash.createGroupByHash (io.prestosql.operator.GroupByHash.createGroupByHash)1 Page (io.prestosql.spi.Page)1 PageBuilder (io.prestosql.spi.PageBuilder)1 Block (io.prestosql.spi.block.Block)1 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)1 TypeUtils.getHashBlock (io.prestosql.type.TypeUtils.getHashBlock)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1