Search in sources :

Example 1 with UnloadedIndexKeyRecordCursor

use of com.facebook.presto.operator.index.UnloadedIndexKeyRecordSet.UnloadedIndexKeyRecordCursor in project presto by prestodb.

the class IndexSnapshotBuilder method createIndexSnapshot.

public IndexSnapshot createIndexSnapshot(UnloadedIndexKeyRecordSet indexKeysRecordSet) {
    checkArgument(indexKeysRecordSet.getColumnTypes().equals(missingKeysTypes), "indexKeysRecordSet must have same schema as missingKeys");
    checkState(!isMemoryExceeded(), "Max memory exceeded");
    for (Page page : pages) {
        outputPagesIndex.addPage(page);
    }
    pages.clear();
    LookupSource lookupSource = outputPagesIndex.createLookupSourceSupplier(session, keyOutputChannels, keyOutputHashChannel, Optional.empty()).get();
    // Build a page containing the keys that produced no output rows, so in future requests can skip these keys
    PageBuilder missingKeysPageBuilder = new PageBuilder(missingKeysIndex.getTypes());
    UnloadedIndexKeyRecordCursor indexKeysRecordCursor = indexKeysRecordSet.cursor();
    while (indexKeysRecordCursor.advanceNextPosition()) {
        Block[] blocks = indexKeysRecordCursor.getBlocks();
        Page page = indexKeysRecordCursor.getPage();
        int position = indexKeysRecordCursor.getPosition();
        if (lookupSource.getJoinPosition(position, page, page) < 0) {
            missingKeysPageBuilder.declarePosition();
            for (int i = 0; i < blocks.length; i++) {
                Block block = blocks[i];
                Type type = indexKeysRecordCursor.getType(i);
                type.appendTo(block, position, missingKeysPageBuilder.getBlockBuilder(i));
            }
        }
    }
    Page missingKeysPage = missingKeysPageBuilder.build();
    memoryInBytes += missingKeysPage.getSizeInBytes();
    if (isMemoryExceeded()) {
        return null;
    }
    // only update missing keys if we have new missing keys
    if (!missingKeysPageBuilder.isEmpty()) {
        missingKeysIndex.addPage(missingKeysPage);
        missingKeys = missingKeysIndex.createLookupSourceSupplier(session, missingKeysChannels).get();
    }
    return new IndexSnapshot(lookupSource, missingKeys);
}
Also used : Type(com.facebook.presto.spi.type.Type) LookupSource(com.facebook.presto.operator.LookupSource) Block(com.facebook.presto.spi.block.Block) Page(com.facebook.presto.spi.Page) PageBuilder(com.facebook.presto.spi.PageBuilder) UnloadedIndexKeyRecordCursor(com.facebook.presto.operator.index.UnloadedIndexKeyRecordSet.UnloadedIndexKeyRecordCursor)

Aggregations

LookupSource (com.facebook.presto.operator.LookupSource)1 UnloadedIndexKeyRecordCursor (com.facebook.presto.operator.index.UnloadedIndexKeyRecordSet.UnloadedIndexKeyRecordCursor)1 Page (com.facebook.presto.spi.Page)1 PageBuilder (com.facebook.presto.spi.PageBuilder)1 Block (com.facebook.presto.spi.block.Block)1 Type (com.facebook.presto.spi.type.Type)1