use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class StatisticsWriterOperator method getOutput.
@Override
public Page getOutput() {
if (state != State.FINISHING) {
return null;
}
state = State.FINISHED;
Collection<ComputedStatistics> computedStatistics = computedStatisticsBuilder.build();
statisticsWriter.writeStatistics(computedStatistics);
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(1, TYPES);
page.declarePosition();
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
if (rowCountEnabled) {
BIGINT.writeLong(rowsBuilder, getRowCount(computedStatistics));
} else {
rowsBuilder.appendNull();
}
return page.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class MergeSortedPages method buildPage.
private static WorkProcessor<Page> buildPage(WorkProcessor<PageWithPosition> pageWithPositions, List<Integer> outputChannels, List<Type> outputTypes, BiPredicate<PageBuilder, PageWithPosition> pageBreakPredicate, boolean updateMemoryAfterEveryPosition, AggregatedMemoryContext aggregatedMemoryContext, DriverYieldSignal yieldSignal) {
LocalMemoryContext memoryContext = aggregatedMemoryContext.newLocalMemoryContext(MergeSortedPages.class.getSimpleName());
PageBuilder pageBuilder = new PageBuilder(outputTypes);
return pageWithPositions.yielding(yieldSignal::isSet).transform(pageWithPositionOptional -> {
boolean finished = !pageWithPositionOptional.isPresent();
if (finished && pageBuilder.isEmpty()) {
memoryContext.close();
return TransformationState.finished();
}
if (finished || pageBreakPredicate.test(pageBuilder, pageWithPositionOptional.get())) {
if (!updateMemoryAfterEveryPosition) {
// update memory usage just before producing page to cap from top
memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
}
Page page = pageBuilder.build();
pageBuilder.reset();
if (!finished) {
pageWithPositionOptional.get().appendTo(pageBuilder, outputChannels, outputTypes);
}
if (updateMemoryAfterEveryPosition) {
memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
}
return TransformationState.ofResult(page, !finished);
}
pageWithPositionOptional.get().appendTo(pageBuilder, outputChannels, outputTypes);
if (updateMemoryAfterEveryPosition) {
memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
}
return TransformationState.needsMoreData();
});
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class TestBlockBuilder method testNewBlockBuilderLikeForLargeBlockBuilder.
@Test
public void testNewBlockBuilderLikeForLargeBlockBuilder() {
if (true) {
throw new SkipException("https://github.com/prestodb/presto/issues/15653 - Skipped because it OOMs");
}
List<Type> channels = ImmutableList.of(VARCHAR);
PageBuilder pageBuilder = new PageBuilder(channels);
BlockBuilder largeVarcharBlockBuilder = pageBuilder.getBlockBuilder(0);
// Construct a string of 64 * 16 = 2^11 bytes
Slice largeSlice = Slices.utf8Slice(String.join("", Collections.nCopies(64, "CowMonsterKing:)")));
// Write the string to the largeVarcharBlockBuilder for 2^20 times
for (int i = 0; i < 1_048_576; i++) {
VARCHAR.writeSlice(largeVarcharBlockBuilder, largeSlice);
pageBuilder.declarePosition();
}
BlockBuilder newVarcharBlockBuilder = largeVarcharBlockBuilder.newBlockBuilderLike(null, 1_048_576 * 8);
assertEquals(newVarcharBlockBuilder.getPositionCount(), 0);
assertEquals(newVarcharBlockBuilder.getRetainedSizeInBytes(), 164);
// We are not going to test real reservation here because allocating large amount of memory fails the Travis.
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
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 com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class TestTypedSet method testGetElementPositionWithProvidedNonEmptyBlockBuilder.
@Test
public void testGetElementPositionWithProvidedNonEmptyBlockBuilder() {
int elementCount = 100;
// Set initialTypedSetEntryCount to a small number to trigger rehash()
int initialTypedSetEntryCount = 10;
PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(BIGINT));
BlockBuilder firstBlockBuilder = pageBuilder.getBlockBuilder(0);
for (int i = 0; i < elementCount; i++) {
BIGINT.writeLong(firstBlockBuilder, i);
}
pageBuilder.declarePositions(elementCount);
// The secondBlockBuilder should already have elementCount rows.
BlockBuilder secondBlockBuilder = pageBuilder.getBlockBuilder(0);
TypedSet typedSet = new TypedSet(BIGINT, secondBlockBuilder, initialTypedSetEntryCount, FUNCTION_NAME);
BlockBuilder externalBlockBuilder = BIGINT.createFixedSizeBlockBuilder(elementCount);
for (int i = 0; i < elementCount; i++) {
if (i % 10 == 0) {
externalBlockBuilder.appendNull();
} else {
BIGINT.writeLong(externalBlockBuilder, i);
}
typedSet.add(externalBlockBuilder, i);
}
assertEquals(typedSet.size(), secondBlockBuilder.getPositionCount() - elementCount);
assertEquals(typedSet.size(), elementCount - elementCount / 10 + 1);
for (int i = 0; i < typedSet.size(); i++) {
int expectedPositionInSecondBlockBuilder = i + elementCount;
assertEquals(typedSet.positionOf(secondBlockBuilder, expectedPositionInSecondBlockBuilder), expectedPositionInSecondBlockBuilder);
}
}
Aggregations