use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.
the class TestGroupByHash method testAppendTo.
@Test
public void testAppendTo() {
Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
Work<GroupByIdBlock> work = groupByHash.getGroupIds(new Page(valuesBlock, hashBlock));
work.process();
GroupByIdBlock groupIds = work.getResult();
for (int i = 0; i < groupIds.getPositionCount(); i++) {
assertEquals(groupIds.getGroupId(i), i);
}
assertEquals(groupByHash.getGroupCount(), 100);
PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
for (int i = 0; i < groupByHash.getGroupCount(); i++) {
pageBuilder.declarePosition();
groupByHash.appendValuesTo(i, pageBuilder, 0);
}
Page page = pageBuilder.build();
// Ensure that all blocks have the same positionCount
for (int i = 0; i < groupByHash.getTypes().size(); i++) {
assertEquals(page.getBlock(i).getPositionCount(), 100);
}
assertEquals(page.getPositionCount(), 100);
BlockAssertions.assertBlockEquals(VARCHAR, page.getBlock(0), valuesBlock);
BlockAssertions.assertBlockEquals(BIGINT, page.getBlock(1), hashBlock);
}
use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.
the class TestGroupByHash method testForceRehash.
@Test
public void testForceRehash() {
// Create a page with positionCount >> expected size of groupByHash
Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
// Create group by hash with extremely small size
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 4, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
// Ensure that all groups are present in group by hash
for (int i = 0; i < valuesBlock.getPositionCount(); i++) {
assertTrue(groupByHash.contains(i, new Page(valuesBlock, hashBlock), CONTAINS_CHANNELS));
}
}
use of io.trino.block.BlockAssertions.createStringSequenceBlock in project trino by trinodb.
the class TestGroupByHash method testContainsMultipleColumns.
@Test
public void testContainsMultipleColumns() {
Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
Block stringValuesBlock = BlockAssertions.createStringSequenceBlock(0, 10);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), valuesBlock, stringValuesBlock);
int[] hashChannels = { 0, 1 };
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE, VARCHAR), hashChannels, Optional.of(2), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
groupByHash.getGroupIds(new Page(valuesBlock, stringValuesBlock, hashBlock)).process();
Block testValuesBlock = BlockAssertions.createDoublesBlock((double) 3);
Block testStringValuesBlock = BlockAssertions.createStringsBlock("3");
Block testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE, VARCHAR), testValuesBlock, testStringValuesBlock);
assertTrue(groupByHash.contains(0, new Page(testValuesBlock, testStringValuesBlock, testHashBlock), hashChannels));
}
Aggregations