use of io.trino.spi.Page 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.spi.Page 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.spi.Page 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.spi.Page in project trino by trinodb.
the class TestGroupByHash method testLowCardinalityDictionariesAddPage.
@Test
public void testLowCardinalityDictionariesAddPage() {
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT, BIGINT), new int[] { 0, 1 }, Optional.empty(), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
Block firstBlock = BlockAssertions.createLongDictionaryBlock(0, 1000, 10);
Block secondBlock = BlockAssertions.createLongDictionaryBlock(0, 1000, 10);
Page page = new Page(firstBlock, secondBlock);
Work<?> work = groupByHash.addPage(page);
assertThat(work).isInstanceOf(MultiChannelGroupByHash.AddLowCardinalityDictionaryPageWork.class);
work.process();
// Blocks are identical so only 10 distinct groups
assertThat(groupByHash.getGroupCount()).isEqualTo(10);
firstBlock = BlockAssertions.createLongDictionaryBlock(10, 1000, 5);
secondBlock = BlockAssertions.createLongDictionaryBlock(10, 1000, 7);
page = new Page(firstBlock, secondBlock);
groupByHash.addPage(page).process();
// Old 10 groups and 35 new
assertThat(groupByHash.getGroupCount()).isEqualTo(45);
}
use of io.trino.spi.Page 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);
}
Aggregations