use of org.apache.hyracks.storage.am.lsm.invertedindex.search.PartitionedTOccurrenceSearcher in project asterixdb by apache.
the class PartitionedOnDiskInvertedIndex method openInvertedListPartitionCursors.
@Override
public boolean openInvertedListPartitionCursors(IInvertedIndexSearcher searcher, IIndexOperationContext ictx, short numTokensLowerBound, short numTokensUpperBound, InvertedListPartitions invListPartitions, List<IInvertedListCursor> cursorsOrderedByTokens) throws HyracksDataException {
PartitionedTOccurrenceSearcher partSearcher = (PartitionedTOccurrenceSearcher) searcher;
OnDiskInvertedIndexOpContext ctx = (OnDiskInvertedIndexOpContext) ictx;
ITupleReference lowSearchKey = null;
ITupleReference highSearchKey = null;
partSearcher.setNumTokensBoundsInSearchKeys(numTokensLowerBound, numTokensUpperBound);
if (numTokensLowerBound < 0) {
ctx.getBtreePred().setLowKeyComparator(ctx.getPrefixSearchCmp());
lowSearchKey = partSearcher.getPrefixSearchKey();
} else {
ctx.getBtreePred().setLowKeyComparator(ctx.getSearchCmp());
lowSearchKey = partSearcher.getFullLowSearchKey();
}
if (numTokensUpperBound < 0) {
ctx.getBtreePred().setHighKeyComparator(ctx.getPrefixSearchCmp());
highSearchKey = partSearcher.getPrefixSearchKey();
} else {
ctx.getBtreePred().setHighKeyComparator(ctx.getSearchCmp());
highSearchKey = partSearcher.getFullHighSearchKey();
}
ctx.getBtreePred().setLowKey(lowSearchKey, true);
ctx.getBtreePred().setHighKey(highSearchKey, true);
ctx.getBtreeAccessor().search(ctx.getBtreeCursor(), ctx.getBtreePred());
boolean tokenExists = false;
try {
while (ctx.getBtreeCursor().hasNext()) {
ctx.getBtreeCursor().next();
ITupleReference btreeTuple = ctx.getBtreeCursor().getTuple();
short numTokens = ShortPointable.getShort(btreeTuple.getFieldData(PARTITIONING_NUM_TOKENS_FIELD), btreeTuple.getFieldStart(PARTITIONING_NUM_TOKENS_FIELD));
IInvertedListCursor invListCursor = partSearcher.getCachedInvertedListCursor();
resetInvertedListCursor(btreeTuple, invListCursor);
cursorsOrderedByTokens.add(invListCursor);
invListPartitions.addInvertedListCursor(invListCursor, numTokens);
tokenExists = true;
}
} finally {
ctx.getBtreeCursor().close();
ctx.getBtreeCursor().reset();
}
return tokenExists;
}
use of org.apache.hyracks.storage.am.lsm.invertedindex.search.PartitionedTOccurrenceSearcher in project asterixdb by apache.
the class PartitionedInMemoryInvertedIndex method openInvertedListPartitionCursors.
@Override
public boolean openInvertedListPartitionCursors(IInvertedIndexSearcher searcher, IIndexOperationContext ictx, short numTokensLowerBound, short numTokensUpperBound, InvertedListPartitions invListPartitions, List<IInvertedListCursor> cursorsOrderedByTokens) throws HyracksDataException {
short minPartitionIndex;
short maxPartitionIndex;
partitionIndexLock.readLock().lock();
minPartitionIndex = this.minPartitionIndex;
maxPartitionIndex = this.maxPartitionIndex;
partitionIndexLock.readLock().unlock();
if (minPartitionIndex == Short.MAX_VALUE && maxPartitionIndex == Short.MIN_VALUE) {
// Index must be empty.
return false;
}
short partitionStartIndex = minPartitionIndex;
short partitionEndIndex = maxPartitionIndex;
if (numTokensLowerBound >= 0) {
partitionStartIndex = (short) Math.max(minPartitionIndex, numTokensLowerBound);
}
if (numTokensUpperBound >= 0) {
partitionEndIndex = (short) Math.min(maxPartitionIndex, numTokensUpperBound);
}
PartitionedTOccurrenceSearcher partSearcher = (PartitionedTOccurrenceSearcher) searcher;
PartitionedInMemoryInvertedIndexOpContext ctx = (PartitionedInMemoryInvertedIndexOpContext) ictx;
ctx.setOperation(IndexOperation.SEARCH);
// We can pick either of the full low or high search key, since they should be identical here.
ITupleReference searchKey = partSearcher.getFullLowSearchKey();
ctx.getBtreePred().setLowKey(searchKey, true);
ctx.getBtreePred().setHighKey(searchKey, true);
// using the last existing partition and re-searching the BTree with an open interval as low key.
for (short i = partitionStartIndex; i <= partitionEndIndex; i++) {
partSearcher.setNumTokensBoundsInSearchKeys(i, i);
InMemoryInvertedListCursor inMemListCursor = (InMemoryInvertedListCursor) partSearcher.getCachedInvertedListCursor();
inMemListCursor.prepare(ctx.getBtreeAccessor(), ctx.getBtreePred(), ctx.getTokenFieldsCmp(), ctx.getBtreeCmp());
inMemListCursor.reset(searchKey);
invListPartitions.addInvertedListCursor(inMemListCursor, i);
}
return true;
}
Aggregations