use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
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(new WorkProcessor.Transformation<PageWithPosition, Page>() {
@RestorableConfig(stateClassName = "BuildPageState", uncapturedFields = { "val$outputTypes", "val$pageBreakPredicate", "val$outputChannels" })
private final RestorableConfig restorableConfig = null;
@Override
public TransformationState<Page> process(@Nullable PageWithPosition pageWithPosition) {
boolean finished = pageWithPosition == null;
if (finished && pageBuilder.isEmpty()) {
memoryContext.close();
return TransformationState.finished();
}
if (finished || pageBreakPredicate.test(pageBuilder, pageWithPosition)) {
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) {
pageWithPosition.appendTo(pageBuilder, outputChannels, outputTypes);
}
if (updateMemoryAfterEveryPosition) {
memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
}
return TransformationState.ofResult(page, !finished);
}
pageWithPosition.appendTo(pageBuilder, outputChannels, outputTypes);
if (updateMemoryAfterEveryPosition) {
memoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
}
return TransformationState.needsMoreData();
}
@Override
public Object captureResult(Page result, BlockEncodingSerdeProvider serdeProvider) {
if (result != null) {
SerializedPage serializedPage = ((PagesSerde) serdeProvider).serialize(result);
return serializedPage.capture(serdeProvider);
}
return null;
}
@Override
public Page restoreResult(Object resultState, BlockEncodingSerdeProvider serdeProvider) {
if (resultState != null) {
return ((PagesSerde) serdeProvider).deserialize(SerializedPage.restoreSerializedPage(resultState));
}
return null;
}
@Override
public Object captureInput(PageWithPosition input, BlockEncodingSerdeProvider serdeProvider) {
if (input != null) {
return input.capture(serdeProvider);
}
return null;
}
@Override
public PageWithPosition restoreInput(Object inputState, PageWithPosition input, BlockEncodingSerdeProvider serdeProvider) {
if (inputState != null) {
return PageWithPosition.restorePageWithPosition(inputState, serdeProvider);
}
return null;
}
@Override
public Object capture(BlockEncodingSerdeProvider serdeProvider) {
BuildPageState myState = new BuildPageState();
myState.pageBuilder = pageBuilder.capture(serdeProvider);
myState.memoryContext = memoryContext.getBytes();
return myState;
}
@Override
public void restore(Object state, BlockEncodingSerdeProvider serdeProvider) {
BuildPageState myState = (BuildPageState) state;
pageBuilder.restore(myState.pageBuilder, serdeProvider);
memoryContext.setBytes(myState.memoryContext);
}
});
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class InMemoryHashAggregationBuilder method buildResult.
protected WorkProcessor<Page> buildResult(IntIterator groupIds) {
final PageBuilder pageBuilder = new PageBuilder(buildTypes());
return WorkProcessor.create(() -> {
if (!groupIds.hasNext()) {
return WorkProcessor.ProcessState.finished();
}
pageBuilder.reset();
List<Type> types = groupBy.getTypes();
while (!pageBuilder.isFull() && groupIds.hasNext()) {
int groupId = groupIds.nextInt();
groupBy.appendValuesTo(groupId, pageBuilder, 0);
pageBuilder.declarePosition();
for (int i = 0; i < aggregators.size(); i++) {
Aggregator aggregator = aggregators.get(i);
BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
aggregator.evaluate(groupId, output);
}
}
return WorkProcessor.ProcessState.ofResult(pageBuilder.build());
});
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class VacuumTableOperator method createFragmentsPage.
private Page createFragmentsPage() {
Collection<Slice> fragments = getFutureValue(finishFuture);
committed = true;
updateWrittenBytes();
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(fragments.size() + 1, ImmutableList.of(types.get(ROW_COUNT_CHANNEL), types.get(FRAGMENT_CHANNEL)));
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
BlockBuilder fragmentBuilder = page.getBlockBuilder(1);
// write row count
page.declarePosition();
BIGINT.writeLong(rowsBuilder, pageSink.getRowsWritten());
fragmentBuilder.appendNull();
// write fragments
for (Slice fragment : fragments) {
page.declarePosition();
rowsBuilder.appendNull();
VARBINARY.writeSlice(fragmentBuilder, fragment);
}
return page.build();
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TableUpdateOperator method getOutput.
@Override
public Page getOutput() {
if (finished) {
return null;
}
finished = true;
OptionalLong rowsUpdatedCount = metadata.executeUpdate(session, tableHandle);
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(1, TYPES);
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
page.declarePosition();
if (rowsUpdatedCount.isPresent()) {
BIGINT.writeLong(rowsBuilder, rowsUpdatedCount.getAsLong());
} else {
rowsBuilder.appendNull();
}
return page.build();
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TableWriterOperator method createFragmentsPage.
private Page createFragmentsPage() {
Collection<Slice> fragments = getFutureValue(finishFuture);
committed = true;
updateWrittenBytes();
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(fragments.size() + 1, ImmutableList.of(types.get(ROW_COUNT_CHANNEL), types.get(FRAGMENT_CHANNEL)));
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
BlockBuilder fragmentBuilder = page.getBlockBuilder(1);
// write row count
page.declarePosition();
BIGINT.writeLong(rowsBuilder, rowCount);
fragmentBuilder.appendNull();
// write fragments
for (Slice fragment : fragments) {
page.declarePosition();
rowsBuilder.appendNull();
VARBINARY.writeSlice(fragmentBuilder, fragment);
}
return page.build();
}
Aggregations