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);
}
Aggregations