Search in sources :

Example 56 with PageBuilder

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

the class PinotSegmentPageSource method fillNextPage.

protected Page fillNextPage() {
    // This is the list of handles we came up with when generating the PQL
    // This could be a superset/permutation of the handles being requested in this scan
    List<PinotColumnHandle> expectedColumnHandles = split.getExpectedColumnHandles();
    PageBuilder pageBuilder = new PageBuilder(columnTypes);
    // Note that declared positions in the Page should be the same with number of rows in each Block
    pageBuilder.declarePositions(currentDataTable.getDataTable().getNumberOfRows());
    for (int columnHandleIndex = 0; columnHandleIndex < columnHandles.size(); columnHandleIndex++) {
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(columnHandleIndex);
        Type columnType = columnTypes.get(columnHandleIndex);
        // Write a block for each column in the original order.
        PinotColumnHandle handle = columnHandles.get(columnHandleIndex);
        // map the handle needed by the scan to its index corresponding to the generated PQL
        // All handles requested by the scan should be a subset of the expected handles
        // ie., the expected column handles (corresponding to the generated PQL) can contain
        // extra columns that we drop.
        int indexReturnedByPinot = expectedColumnHandles.indexOf(handle);
        if (indexReturnedByPinot < 0) {
            throw new PinotException(PINOT_INVALID_PQL_GENERATED, split.getSegmentPinotQuery(), String.format("Expected column handle %s to be present in the handles %s corresponding to the segment PQL", handle, expectedColumnHandles));
        }
        writeBlock(blockBuilder, columnType, indexReturnedByPinot);
    }
    return pageBuilder.build();
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 57 with PageBuilder

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

the class TestShardCompactor method sortAndMaterialize.

private static MaterializedResult sortAndMaterialize(List<Page> pages, List<Type> columnTypes, List<Integer> sortIndexes, List<SortOrder> sortOrders, List<Type> sortTypes) {
    long[] orderedAddresses = PAGE_SORTER.sort(columnTypes, pages, sortIndexes, sortOrders, 10_000);
    PageBuilder pageBuilder = new PageBuilder(columnTypes);
    for (long orderedAddress : orderedAddresses) {
        int pageIndex = PAGE_SORTER.decodePageIndex(orderedAddress);
        int positionIndex = PAGE_SORTER.decodePositionIndex(orderedAddress);
        Page page = pages.get(pageIndex);
        pageBuilder.declarePosition();
        for (int i = 0; i < columnTypes.size(); i++) {
            columnTypes.get(i).appendTo(page.getBlock(i), positionIndex, pageBuilder.getBlockBuilder(i));
        }
    }
    // extract the sortIndexes and reorder the blocks by sort indexes (useful for debugging)
    Page buildPage = pageBuilder.build();
    Block[] outputBlocks = new Block[buildPage.getChannelCount()];
    for (int i = 0; i < sortIndexes.size(); i++) {
        outputBlocks[i] = buildPage.getBlock(sortIndexes.get(i));
    }
    MaterializedResult.Builder resultBuilder = MaterializedResult.resultBuilder(SESSION, sortTypes);
    resultBuilder.page(new Page(outputBlocks));
    return resultBuilder.build();
}
Also used : Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) SequencePageBuilder(com.facebook.presto.SequencePageBuilder) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Aggregations

PageBuilder (com.facebook.presto.common.PageBuilder)57 Page (com.facebook.presto.common.Page)27 Type (com.facebook.presto.common.type.Type)25 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)23 ImmutableList (com.google.common.collect.ImmutableList)14 Block (com.facebook.presto.common.block.Block)11 Test (org.testng.annotations.Test)11 ArrayType (com.facebook.presto.common.type.ArrayType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Benchmark (org.openjdk.jmh.annotations.Benchmark)7 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)3 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)3 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)3 Slices (io.airlift.slice.Slices)3 File (java.io.File)3