use of io.trino.type.TypeTestUtils.getHashBlock 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.type.TypeTestUtils.getHashBlock in project trino by trinodb.
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 = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), valuesBlock);
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
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));
}
use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.
the class TestGroupByHash method testContains.
@Test
public void testContains() {
Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), valuesBlock);
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
Block testBlock = BlockAssertions.createDoublesBlock((double) 3);
Block testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
assertTrue(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
testBlock = BlockAssertions.createDoublesBlock(11.0);
testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
assertFalse(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
}
use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.
the class TestGroupByHash method testRunLengthEncodedBigintGroupByHash.
@Test
public void testRunLengthEncodedBigintGroupByHash() {
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
Block block = BlockAssertions.createLongsBlock(0L);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
Page page = new Page(new RunLengthEncodedBlock(block, 2), new RunLengthEncodedBlock(hashBlock, 2));
groupByHash.addPage(page).process();
assertEquals(groupByHash.getGroupCount(), 1);
Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
work.process();
GroupByIdBlock groupIds = work.getResult();
assertEquals(groupIds.getGroupCount(), 1);
assertEquals(groupIds.getPositionCount(), 2);
assertEquals(groupIds.getGroupId(0), 0);
assertEquals(groupIds.getGroupId(1), 0);
List<Block> children = groupIds.getChildren();
assertEquals(children.size(), 1);
assertTrue(children.get(0) instanceof RunLengthEncodedBlock);
}
use of io.trino.type.TypeTestUtils.getHashBlock 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));
}
}
Aggregations