Search in sources :

Example 6 with TypeUtils.getHashBlock

use of com.facebook.presto.type.TypeUtils.getHashBlock in project presto by prestodb.

the class TestGroupByHash method testContains.

@Test
public void testContains() throws Exception {
    Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
    Block hashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock));
    Block testBlock = BlockAssertions.createDoublesBlock((double) 3);
    Block testHashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
    assertTrue(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
    testBlock = BlockAssertions.createDoublesBlock(11.0);
    testHashBlock = TypeUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
    assertFalse(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
}
Also used : GroupByHash.createGroupByHash(com.facebook.presto.operator.GroupByHash.createGroupByHash) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) TypeUtils.getHashBlock(com.facebook.presto.type.TypeUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) Page(com.facebook.presto.spi.Page) Test(org.testng.annotations.Test)

Example 7 with TypeUtils.getHashBlock

use of com.facebook.presto.type.TypeUtils.getHashBlock in project presto by prestodb.

the class TestGroupByHash method testGetGroupIds.

@Test
public void testGetGroupIds() throws Exception {
    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++) {
                GroupByIdBlock groupIds = groupByHash.getGroupIds(page);
                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(com.facebook.presto.operator.GroupByHash.createGroupByHash) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) TypeUtils.getHashBlock(com.facebook.presto.type.TypeUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) Page(com.facebook.presto.spi.Page) Test(org.testng.annotations.Test)

Aggregations

BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)7 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)7 GroupByHash.createGroupByHash (com.facebook.presto.operator.GroupByHash.createGroupByHash)7 Page (com.facebook.presto.spi.Page)7 Block (com.facebook.presto.spi.block.Block)7 TypeUtils.getHashBlock (com.facebook.presto.type.TypeUtils.getHashBlock)7 Test (org.testng.annotations.Test)7 PageBuilder (com.facebook.presto.spi.PageBuilder)2 ArrayList (java.util.ArrayList)1