Search in sources :

Example 11 with PageBuilder

use of com.facebook.presto.spi.PageBuilder in project presto by prestodb.

the class GenericPageProcessor method processColumnar.

@Override
public Page processColumnar(ConnectorSession session, Page page, List<? extends Type> types) {
    int[] selectedPositions = filterPage(page);
    if (selectedPositions.length == 0) {
        return null;
    }
    if (projections.isEmpty()) {
        return new Page(selectedPositions.length);
    }
    PageBuilder pageBuilder = new PageBuilder(types);
    Block[] inputBlocks = page.getBlocks();
    for (int projectionIndex = 0; projectionIndex < projections.size(); projectionIndex++) {
        ProjectionFunction projection = projections.get(projectionIndex);
        projectColumnar(selectedPositions, pageBuilder.getBlockBuilder(projectionIndex), inputBlocks, projection);
    }
    pageBuilder.declarePositions(selectedPositions.length);
    return pageBuilder.build();
}
Also used : Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) Page(com.facebook.presto.spi.Page) PageBuilder(com.facebook.presto.spi.PageBuilder)

Example 12 with PageBuilder

use of com.facebook.presto.spi.PageBuilder in project presto by prestodb.

the class DeleteOperator method getOutput.

@Override
public Page getOutput() {
    if ((state != State.FINISHING) || !finishFuture.isDone()) {
        return null;
    }
    state = State.FINISHED;
    Collection<Slice> fragments = getFutureValue(finishFuture);
    PageBuilder page = new PageBuilder(TYPES);
    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();
}
Also used : Slice(io.airlift.slice.Slice) PageBuilder(com.facebook.presto.spi.PageBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 13 with PageBuilder

use of com.facebook.presto.spi.PageBuilder in project presto by prestodb.

the class MetadataDeleteOperator method getOutput.

@Override
public Page getOutput() {
    if (finished) {
        return null;
    }
    finished = true;
    OptionalLong rowsDeletedCount = metadata.metadataDelete(session, tableHandle, tableLayout);
    PageBuilder page = new PageBuilder(TYPES);
    BlockBuilder rowsBuilder = page.getBlockBuilder(0);
    page.declarePosition();
    if (rowsDeletedCount.isPresent()) {
        BIGINT.writeLong(rowsBuilder, rowsDeletedCount.getAsLong());
    } else {
        rowsBuilder.appendNull();
    }
    return page.build();
}
Also used : OptionalLong(java.util.OptionalLong) PageBuilder(com.facebook.presto.spi.PageBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 14 with PageBuilder

use of com.facebook.presto.spi.PageBuilder in project presto by prestodb.

the class RowNumberOperator method getSelectedRows.

private Page getSelectedRows() {
    PageBuilder pageBuilder = new PageBuilder(types);
    int rowNumberChannel = types.size() - 1;
    for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
        long partitionId = getPartitionId(currentPosition);
        long rowCount = partitionRowCount.get(partitionId);
        if (rowCount == maxRowsPerPartition.get()) {
            continue;
        }
        pageBuilder.declarePosition();
        for (int i = 0; i < outputChannels.length; i++) {
            int channel = outputChannels[i];
            Type type = types.get(i);
            type.appendTo(inputPage.getBlock(channel), currentPosition, pageBuilder.getBlockBuilder(i));
        }
        BIGINT.writeLong(pageBuilder.getBlockBuilder(rowNumberChannel), rowCount + 1);
        partitionRowCount.set(partitionId, rowCount + 1);
    }
    if (pageBuilder.isEmpty()) {
        return null;
    }
    return pageBuilder.build();
}
Also used : Type(com.facebook.presto.spi.type.Type) PageBuilder(com.facebook.presto.spi.PageBuilder)

Example 15 with PageBuilder

use of com.facebook.presto.spi.PageBuilder in project presto by prestodb.

the class TupleFilterProcessor method processColumnar.

@Override
public Page processColumnar(ConnectorSession session, Page page, List<? extends Type> types) {
    PageBuilder pageBuilder = new PageBuilder(types);
    int positionCount = page.getPositionCount();
    int[] selectedPositions = new int[positionCount];
    int selectedCount = 0;
    for (int i = 0; i < positionCount; i++) {
        if (matches(i, page)) {
            selectedPositions[selectedCount++] = i;
        }
    }
    for (int i = 0; i < outputTypes.size(); i++) {
        Type type = outputTypes.get(i);
        Block block = page.getBlock(i);
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
        for (int position : selectedPositions) {
            type.appendTo(block, position, blockBuilder);
        }
    }
    pageBuilder.declarePositions(selectedCount);
    return pageBuilder.build();
}
Also used : Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) PageBuilder(com.facebook.presto.spi.PageBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Aggregations

PageBuilder (com.facebook.presto.spi.PageBuilder)45 Page (com.facebook.presto.spi.Page)23 Block (com.facebook.presto.spi.block.Block)16 Type (com.facebook.presto.spi.type.Type)15 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)14 ImmutableList (com.google.common.collect.ImmutableList)12 Test (org.testng.annotations.Test)10 List (java.util.List)7 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)4 Parameter (com.facebook.presto.bytecode.Parameter)4 Variable (com.facebook.presto.bytecode.Variable)4 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)4 LazyBlock (com.facebook.presto.spi.block.LazyBlock)4 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)4 ArrayList (java.util.ArrayList)4 SequencePageBuilder (com.facebook.presto.SequencePageBuilder)3 Scope (com.facebook.presto.bytecode.Scope)3 IfStatement (com.facebook.presto.bytecode.control.IfStatement)3