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));
}
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);
}
}
}
}
Aggregations