use of com.facebook.presto.common.Page in project presto by prestodb.
the class WindowOperator method updatePagesIndex.
private int updatePagesIndex(PagesIndexWithHashStrategies pagesIndexWithHashStrategies, Page page, int startPosition, Optional<Page> currentSpillGroupRowPage) {
checkArgument(page.getPositionCount() > startPosition);
// TODO: Fix pagesHashStrategy to allow specifying channels for comparison, it currently requires us to rearrange the right side blocks in consecutive channel order
Page preGroupedPage = page.extractChannels(pagesIndexWithHashStrategies.preGroupedPartitionChannels);
PagesIndex pagesIndex = pagesIndexWithHashStrategies.pagesIndex;
PagesHashStrategy preGroupedPartitionHashStrategy = pagesIndexWithHashStrategies.preGroupedPartitionHashStrategy;
if (currentSpillGroupRowPage.isPresent()) {
if (!preGroupedPartitionHashStrategy.rowEqualsRow(0, currentSpillGroupRowPage.get().extractChannels(pagesIndexWithHashStrategies.preGroupedPartitionChannels), startPosition, preGroupedPage)) {
return startPosition;
}
}
if (pagesIndex.getPositionCount() == 0 || pagesIndex.positionEqualsRow(preGroupedPartitionHashStrategy, 0, startPosition, preGroupedPage)) {
// Find the position where the pre-grouped columns change
int groupEnd = findGroupEnd(preGroupedPage, preGroupedPartitionHashStrategy, startPosition);
// Add the section of the page that contains values for the current group
pagesIndex.addPage(page.getRegion(startPosition, groupEnd - startPosition));
if (page.getPositionCount() - groupEnd > 0) {
// Save the remaining page, which may contain multiple partitions
return groupEnd;
} else {
// Page fully consumed
return page.getPositionCount();
}
} else {
// We had previous results buffered, but the remaining page starts with new group values
return startPosition;
}
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class TableFinishOperator method getOutput.
@Override
public Page getOutput() {
if (!isBlocked().isDone()) {
return null;
}
if (!statisticsAggregationOperator.isFinished()) {
verify(statisticsAggregationOperator.isBlocked().isDone(), "aggregation operator should not be blocked");
OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled);
Page page = statisticsAggregationOperator.getOutput();
timer.end(statisticsTiming);
if (page == null) {
return null;
}
for (int position = 0; position < page.getPositionCount(); position++) {
computedStatisticsBuilder.add(getComputedStatistics(page, position));
}
return null;
}
if (state != State.FINISHING) {
return null;
}
state = State.FINISHED;
lifespanAndStageStateTracker.commit();
outputMetadata.set(tableFinisher.finishTable(lifespanAndStageStateTracker.getFinalFragments(), computedStatisticsBuilder.build()));
// 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();
BIGINT.writeLong(page.getBlockBuilder(0), lifespanAndStageStateTracker.getFinalRowCount());
return page.build();
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class TableWriterOperator method createFragmentsPage.
// Fragments page layout:
//
// row fragments context
// X null X
// null X X
// null X X
// null X X
// ...
private Page createFragmentsPage() {
Collection<Slice> fragments = getFutureValue(finishFuture);
int positionCount = fragments.size() + 1;
committed = true;
updateWrittenBytes();
// Output page will only be constructed once, and the table commit context channel will be constructed using RunLengthEncodedBlock.
// Thus individual BlockBuilder is used for each channel, instead of using PageBuilder.
BlockBuilder rowsBuilder = BIGINT.createBlockBuilder(null, positionCount);
BlockBuilder fragmentBuilder = VARBINARY.createBlockBuilder(null, positionCount);
// write row count
BIGINT.writeLong(rowsBuilder, rowCount);
fragmentBuilder.appendNull();
// write fragments
for (Slice fragment : fragments) {
rowsBuilder.appendNull();
VARBINARY.writeSlice(fragmentBuilder, fragment);
}
return new Page(positionCount, rowsBuilder.build(), fragmentBuilder.build(), RunLengthEncodedBlock.create(VARBINARY, createTableCommitContext(true), positionCount));
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class TableWriterOperator method addInput.
@Override
public void addInput(Page page) {
requireNonNull(page, "page is null");
checkState(needsInput(), "Operator does not need input");
Block[] blocks = new Block[columnChannels.size()];
for (int outputChannel = 0; outputChannel < columnChannels.size(); outputChannel++) {
Block block = page.getBlock(columnChannels.get(outputChannel));
String columnName = notNullChannelColumnNames.get(outputChannel);
if (columnName != null) {
verifyBlockHasNoNulls(block, columnName);
}
blocks[outputChannel] = block;
}
OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled);
statisticAggregationOperator.addInput(page);
timer.end(statisticsTiming);
ListenableFuture<?> blockedOnAggregation = statisticAggregationOperator.isBlocked();
CompletableFuture<?> future = pageSink.appendPage(new Page(blocks));
updateMemoryUsage();
ListenableFuture<?> blockedOnWrite = toListenableFuture(future);
blocked = allAsList(blockedOnAggregation, blockedOnWrite);
rowCount += page.getPositionCount();
updateWrittenBytes();
}
use of com.facebook.presto.common.Page in project presto by prestodb.
the class RemoteProjectOperator method getOutput.
@Override
public Page getOutput() {
if (resultReady()) {
Block[] blocks = new Block[result.length];
Page output;
try {
for (int i = 0; i < blocks.length; i++) {
blocks[i] = result[i].get().getResult();
operatorContext.recordAdditionalCpu(MILLISECONDS.toNanos(result[i].get().getCpuTimeMs()));
}
output = new Page(blocks);
Arrays.fill(result, null);
return output;
} catch (InterruptedException ie) {
currentThread().interrupt();
throw new RuntimeException(ie);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause != null) {
throwIfUnchecked(cause);
throw new PrestoException(GENERIC_INTERNAL_ERROR, cause);
}
throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
}
}
return null;
}
Aggregations