use of com.facebook.presto.block.BlockAssertions.createLongsBlock in project presto by prestodb.
the class TestGroupByHash method testAppendToMultipleTuplesPerGroup.
@Test
public void testAppendToMultipleTuplesPerGroup() throws Exception {
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));
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));
}
use of com.facebook.presto.block.BlockAssertions.createLongsBlock in project presto by prestodb.
the class TestGroupByHash method testAddPage.
@Test
public void testAddPage() 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++) {
groupByHash.addPage(page);
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
GroupByIdBlock groupIds = groupByHash.getGroupIds(page);
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);
}
}
}
}
use of com.facebook.presto.block.BlockAssertions.createLongsBlock 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