use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class MultiChannelGroupByHash method startNewPage.
private void startNewPage() {
if (currentPageBuilder != null) {
completedPagesMemorySize += currentPageBuilder.getRetainedSizeInBytes();
currentPageBuilder = currentPageBuilder.newPageBuilderLike();
} else {
currentPageBuilder = new PageBuilder(types);
}
for (int i = 0; i < types.size(); i++) {
channelBuilders.get(i).add(currentPageBuilder.getBlockBuilder(i));
}
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TestPagesIndexPageSorter method createOutputPages.
private static List<Page> createOutputPages(List<Type> types, List<Page> inputPages, long[] sortedAddresses) {
PageBuilder pageBuilder = new PageBuilder(types);
pageBuilder.reset();
for (long address : sortedAddresses) {
int index = sorter.decodePageIndex(address);
int position = sorter.decodePositionIndex(address);
Page page = inputPages.get(index);
for (int i = 0; i < types.size(); i++) {
Type type = types.get(i);
type.appendTo(page.getBlock(i), position, pageBuilder.getBlockBuilder(i));
}
pageBuilder.declarePosition();
}
return ImmutableList.of(pageBuilder.build());
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TestBlockBuilder method testNewBlockBuilderLike.
@Test
public void testNewBlockBuilderLike() {
ArrayType longArrayType = new ArrayType(BIGINT);
ArrayType arrayType = new ArrayType(longArrayType);
List<Type> channels = ImmutableList.of(BIGINT, VARCHAR, arrayType);
PageBuilder pageBuilder = new PageBuilder(channels);
BlockBuilder bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
BlockBuilder arrayBlockBuilder = pageBuilder.getBlockBuilder(2);
for (int i = 0; i < 100; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
Block longArrayBlock = new ArrayType(BIGINT).createBlockBuilder(null, 1).appendStructure(BIGINT.createBlockBuilder(null, 2).writeLong(i).closeEntry().writeLong(i * 2).closeEntry().build());
arrayBlockBuilder.appendStructure(longArrayBlock);
pageBuilder.declarePosition();
}
PageBuilder newPageBuilder = pageBuilder.newPageBuilderLike();
for (int i = 0; i < channels.size(); i++) {
assertEquals(newPageBuilder.getType(i), pageBuilder.getType(i));
// we should get new block builder instances
assertNotEquals(pageBuilder.getBlockBuilder(i), newPageBuilder.getBlockBuilder(i));
assertEquals(newPageBuilder.getBlockBuilder(i).getPositionCount(), 0);
assertTrue(newPageBuilder.getBlockBuilder(i).getRetainedSizeInBytes() < pageBuilder.getBlockBuilder(i).getRetainedSizeInBytes());
}
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TestBlockBuilder method testPageBuilderBlockBuilderSnapshot.
@Test
public void testPageBuilderBlockBuilderSnapshot() {
PagesSerde serde = TestingPagesSerdeFactory.testingPagesSerde();
List<Type> channels = ImmutableList.of(BIGINT, VARCHAR, INTEGER);
PageBuilder pageBuilder = new PageBuilder(channels);
BlockBuilder bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
BlockBuilder intBlockBuilder = pageBuilder.getBlockBuilder(2);
for (int i = 0; i < 100; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
INTEGER.writeLong(intBlockBuilder, i);
pageBuilder.declarePosition();
}
Page withoutRestore = pageBuilder.build();
pageBuilder.reset();
bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
intBlockBuilder = pageBuilder.getBlockBuilder(2);
for (int i = 0; i < 50; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
INTEGER.writeLong(intBlockBuilder, i);
pageBuilder.declarePosition();
}
Object snapshot = pageBuilder.capture(serde);
for (int i = 50; i < 90; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
INTEGER.writeLong(intBlockBuilder, i);
pageBuilder.declarePosition();
}
pageBuilder.restore(snapshot, serde);
for (int i = 50; i < 100; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
INTEGER.writeLong(intBlockBuilder, i);
pageBuilder.declarePosition();
}
Page withRestore = pageBuilder.build();
assertPageEquals(channels, withRestore, withoutRestore);
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
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 = 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)).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));
}
Aggregations