Search in sources :

Example 86 with Page

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;
    }
}
Also used : Page(com.facebook.presto.common.Page)

Example 87 with Page

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();
}
Also used : Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder)

Example 88 with Page

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));
}
Also used : Slice(io.airlift.slice.Slice) Page(com.facebook.presto.common.Page) TableWriterUtils.createStatisticsPage(com.facebook.presto.operator.TableWriterUtils.createStatisticsPage) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 89 with Page

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();
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) TableWriterUtils.createStatisticsPage(com.facebook.presto.operator.TableWriterUtils.createStatisticsPage)

Example 90 with Page

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;
}
Also used : Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) PrestoException(com.facebook.presto.spi.PrestoException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Page (com.facebook.presto.common.Page)545 Test (org.testng.annotations.Test)273 Block (com.facebook.presto.common.block.Block)146 Type (com.facebook.presto.common.type.Type)129 MaterializedResult (com.facebook.presto.testing.MaterializedResult)102 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)89 ImmutableList (com.google.common.collect.ImmutableList)73 DataSize (io.airlift.units.DataSize)69 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)65 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)52 ArrayList (java.util.ArrayList)50 List (java.util.List)48 Optional (java.util.Optional)44 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)43 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)38 PrestoException (com.facebook.presto.spi.PrestoException)38 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)36 ArrayType (com.facebook.presto.common.type.ArrayType)35 IOException (java.io.IOException)31 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)29