Search in sources :

Example 1 with BlockAssertions.createLongsBlock

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

the class TestGroupByHash method testAddPageSnapshot.

@Test
public void testAddPageSnapshot() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    Object snapshot = null;
    boolean restored = false;
    for (int tries = 0; tries < 2; tries++) {
        for (int value = 0; value < MAX_GROUP_ID; value++) {
            Block block = BlockAssertions.createLongsBlock(value);
            Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), block);
            Page page = new Page(block, hashBlock);
            for (int addValuesTries = 0; addValuesTries < 10; addValuesTries++) {
                groupByHash.addPage(page).process();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // add the page again using get group ids and make sure the group count didn't change
                Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
                work.process();
                GroupByIdBlock groupIds = work.getResult();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                assertEquals(groupIds.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // verify the first position
                assertEquals(groupIds.getPositionCount(), 1);
                long groupId = groupIds.getGroupId(0);
                assertEquals(groupId, value);
            }
        }
        if (tries == 0) {
            snapshot = groupByHash.capture(null);
            assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createBigintExpectedMapping());
        } else if (tries == 1 && !restored) {
            // restore and go back to tries = 0
            groupByHash.restore(snapshot, null);
            snapshot = groupByHash.capture(null);
            assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createBigintExpectedMapping());
            tries--;
            restored = true;
        }
    }
}
Also used : 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) Test(org.testng.annotations.Test)

Example 2 with BlockAssertions.createLongsBlock

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

the class TestGroupByHash method testGetGroupIds.

@Test
public void testGetGroupIds() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    for (int tries = 0; tries < 2; tries++) {
        for (int value = 0; value < MAX_GROUP_ID; value++) {
            Block block = BlockAssertions.createLongsBlock(value);
            Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), block);
            Page page = new Page(block, hashBlock);
            for (int addValuesTries = 0; addValuesTries < 10; addValuesTries++) {
                Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
                work.process();
                GroupByIdBlock groupIds = work.getResult();
                assertEquals(groupIds.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                assertEquals(groupIds.getPositionCount(), 1);
                long groupId = groupIds.getGroupId(0);
                assertEquals(groupId, value);
            }
        }
    }
}
Also used : 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) Test(org.testng.annotations.Test)

Example 3 with BlockAssertions.createLongsBlock

use of io.prestosql.block.BlockAssertions.createLongsBlock 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)

Example 4 with BlockAssertions.createLongsBlock

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

the class TestGroupByHash method testAddPage.

@Test
public void testAddPage() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    for (int tries = 0; tries < 2; tries++) {
        for (int value = 0; value < MAX_GROUP_ID; value++) {
            Block block = BlockAssertions.createLongsBlock(value);
            Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(BIGINT), block);
            Page page = new Page(block, hashBlock);
            for (int addValuesTries = 0; addValuesTries < 10; addValuesTries++) {
                groupByHash.addPage(page).process();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // add the page again using get group ids and make sure the group count didn't change
                Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
                work.process();
                GroupByIdBlock groupIds = work.getResult();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                assertEquals(groupIds.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // verify the first position
                assertEquals(groupIds.getPositionCount(), 1);
                long groupId = groupIds.getGroupId(0);
                assertEquals(groupId, value);
            }
        }
    }
}
Also used : 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) Test(org.testng.annotations.Test)

Aggregations

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