protected IIndexCursor createCursor() throws HyracksDataException { return indexAccessor.createSearchCursor(false); }
protected IIndexCursor createCursor(IIndexAccessor accessor) throws Exception { return accessor.createSearchCursor(false); }
@Override public boolean doHasNext() throws HyracksDataException { if (!tupleConsumed) { return true; } if (currentCursor != null) { if (nextValidTuple()) { return true; } currentCursor.close(); accessorIndex++; } while (accessorIndex < indexAccessors.size()) { // Current cursor has been exhausted, switch to next accessor/cursor. currentAccessor = indexAccessors.get(accessorIndex); currentCursor = currentAccessor.createSearchCursor(false); currentAccessor.search(currentCursor, searchPred); if (nextValidTuple()) { return true; } // Close as we go to release resources. currentCursor.close(); accessorIndex++; } return false; }
@Override protected IIndexAccessor createAccessor() throws HyracksDataException { EnforcedIndexCursor cursor = new DummyEnforcedIndexCursor(); IIndexAccessor accessor = Mockito.mock(IIndexAccessor.class); Mockito.when(accessor.createSearchCursor(Mockito.anyBoolean())).thenReturn(cursor); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); IIndexCursor cursor = (IIndexCursor) args[0]; ISearchPredicate pred = (ISearchPredicate) args[1]; cursor.open(null, pred); return null; } }).when(accessor).search(Matchers.any(IIndexCursor.class), Matchers.any(ISearchPredicate.class)); return accessor; } }
for (int i = 0; i < operationalComponents.size(); i++) { ILSMComponent component = operationalComponents.get(i); deletedKeysBTreeCursors[i] = deletedKeysBTreeAccessors.get(i).createSearchCursor(false); if (component.getType() == LSMComponentType.MEMORY) {
@Override public void doOpen(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException { LSMInvertedIndexSearchCursorInitialState lsmInitState = (LSMInvertedIndexSearchCursorInitialState) initialState; harness = lsmInitState.getLSMHarness(); operationalComponents = lsmInitState.getOperationalComponents(); indexAccessors = lsmInitState.getIndexAccessors(); opCtx = lsmInitState.getOpContext(); accessorIndex = 0; this.searchPred = searchPred; this.searchCallback = lsmInitState.getSearchOperationCallback(); includeMemoryComponents = false; // For searching the deleted-keys BTrees. deletedKeysBTreeAccessors = lsmInitState.getDeletedKeysBTreeAccessors(); deletedKeysBTreeCursors = new IIndexCursor[deletedKeysBTreeAccessors.size()]; deletedKeysBTreeBloomFilters = new BloomFilter[deletedKeysBTreeAccessors.size()]; for (int i = 0; i < operationalComponents.size(); i++) { ILSMComponent component = operationalComponents.get(i); deletedKeysBTreeCursors[i] = deletedKeysBTreeAccessors.get(i).createSearchCursor(false); if (component.getType() == LSMComponentType.MEMORY) { // No need for a bloom filter for the in-memory BTree. deletedKeysBTreeBloomFilters[i] = null; includeMemoryComponents = true; } else { deletedKeysBTreeBloomFilters[i] = ((LSMInvertedIndexDiskComponent) component).getBloomFilter(); } } MultiComparator keyCmp = lsmInitState.getKeyComparator(); keySearchPred = new RangePredicate(null, null, true, true, keyCmp, keyCmp); }
public OnDiskInvertedIndexOpContext(BTree btree) throws HyracksDataException { // TODO: Ignore opcallbacks for now. btreeAccessor = btree.createAccessor(NoOpIndexAccessParameters.INSTANCE); btreeCursor = btreeAccessor.createSearchCursor(false); searchCmp = MultiComparator.create(btree.getComparatorFactories()); if (btree.getComparatorFactories().length > 1) { prefixSearchCmp = MultiComparator.create(btree.getComparatorFactories(), 0, 1); } }
public SearchTask() throws HyracksDataException { this.cb = new SynchronizingSearchOperationCallback(); IndexAccessParameters actx = new IndexAccessParameters(NoOpOperationCallback.INSTANCE, cb); this.accessor = index.createAccessor(actx); this.cursor = accessor.createSearchCursor(false); this.predicate = new RangePredicate(); this.builder = new ArrayTupleBuilder(NUM_KEY_FIELDS); this.tuple = new ArrayTupleReference(); this.blockOnHigh = false; this.blockingValue = -1; this.expectedAfterBlock = -1; }
private <T> void search(IIndexAccessor indexAccessor, RangePredicate rangePred, List<T> results, IValueExtractor<T> valueExtractor, TxnId txnId) throws HyracksDataException, RemoteException, AlgebricksException { IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false); try { indexAccessor.search(rangeCursor, rangePred); try { while (rangeCursor.hasNext()) { rangeCursor.next(); T result = valueExtractor.getValue(txnId, rangeCursor.getTuple()); if (result != null) { results.add(result); } } } finally { rangeCursor.close(); } } finally { rangeCursor.destroy(); } }
protected void scan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception { if (LOGGER.isInfoEnabled()) { LOGGER.info("Scan:"); } IIndexCursor scanCursor = indexAccessor.createSearchCursor(false); try { SearchPredicate nullPred = new SearchPredicate(null, null); indexAccessor.search(scanCursor, nullPred); try { while (scanCursor.hasNext()) { scanCursor.next(); ITupleReference frameTuple = scanCursor.getTuple(); String rec = TupleUtils.printTuple(frameTuple, fieldSerdes); if (LOGGER.isInfoEnabled()) { LOGGER.info(rec); } } } finally { scanCursor.close(); } } finally { scanCursor.destroy(); } }
protected void orderedScan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception { if (LOGGER.isInfoEnabled()) { LOGGER.info("Ordered Scan:"); } IIndexCursor scanCursor = indexAccessor.createSearchCursor(false); try { RangePredicate nullPred = new RangePredicate(null, null, true, true, null, null); indexAccessor.search(scanCursor, nullPred); try { while (scanCursor.hasNext()) { scanCursor.next(); ITupleReference frameTuple = scanCursor.getTuple(); String rec = TupleUtils.printTuple(frameTuple, fieldSerdes); if (LOGGER.isInfoEnabled()) { LOGGER.info(rec); } } } finally { scanCursor.close(); } } finally { scanCursor.destroy(); } }
@Override public void doOpen(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException { LSMInvertedIndexRangeSearchCursorInitialState lsmInitialState = (LSMInvertedIndexRangeSearchCursorInitialState) initialState; cmp = lsmInitialState.getOriginalKeyComparator(); operationalComponents = lsmInitialState.getOperationalComponents(); // We intentionally set the lsmHarness to null so that we don't call lsmHarness.endSearch() because we already // do that when we merge the inverted indexes. lsmHarness = null; int numBTrees = operationalComponents.size(); rangeCursors = new IIndexCursor[numBTrees]; MultiComparator keyCmp = lsmInitialState.getKeyComparator(); RangePredicate btreePredicate = new RangePredicate(null, null, true, true, keyCmp, keyCmp); ArrayList<IIndexAccessor> btreeAccessors = lsmInitialState.getDeletedKeysBTreeAccessors(); for (int i = 0; i < numBTrees; i++) { rangeCursors[i] = btreeAccessors.get(i).createSearchCursor(false); } IndexCursorUtils.open(btreeAccessors, rangeCursors, btreePredicate); try { setPriorityQueueComparator(); initPriorityQueue(); } catch (Throwable th) { // NOSONAR: Must catch all failures IndexCursorUtils.close(rangeCursors, th); throw HyracksDataException.create(th); } } }
@SuppressWarnings("unchecked") public void checkScan(IIndexTestContext ctx) throws Exception { if (LOGGER.isInfoEnabled()) { LOGGER.info("Testing Scan."); } IIndexCursor scanCursor = ctx.getIndexAccessor().createSearchCursor(false); try { ISearchPredicate nullPred = createNullSearchPredicate(); ctx.getIndexAccessor().search(scanCursor, nullPred); try { Iterator<CheckTuple> checkIter = ctx.getCheckTuples().iterator(); checkExpectedResults(scanCursor, ctx.getCheckTuples(), ctx.getFieldSerdes(), ctx.getKeyFieldCount(), checkIter); } finally { scanCursor.close(); } } finally { scanCursor.destroy(); } }
rangePred = new SearchPredicate(key, cmp); IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false); try { indexAccessor.search(rangeCursor, rangePred);
public OnDiskInvertedIndexRangeSearchCursor(OnDiskInvertedIndex invIndex, IIndexOperationContext opCtx) throws HyracksDataException { this.btree = invIndex.getBTree(); this.btreeAccessor = btree.createAccessor(NoOpIndexAccessParameters.INSTANCE); this.invIndex = invIndex; this.opCtx = opCtx; // Project away non-token fields of the BTree tuples. int[] fieldPermutation = new int[invIndex.getTokenTypeTraits().length]; for (int i = 0; i < invIndex.getTokenTypeTraits().length; i++) { fieldPermutation[i] = i; } tokenTuple = new PermutingTupleReference(fieldPermutation); btreeCursor = btreeAccessor.createSearchCursor(false); resultTuple = new TokenKeyPairTuple(invIndex.getTokenTypeTraits().length, btree.getCmpFactories().length); invListRangeSearchCursor = invIndex.createInvertedListRangeSearchCursor(); isInvListCursorOpen = false; }
@Override public void validate() throws HyracksDataException { btree.validate(); // Scan the btree and validate the order of elements in each inverted-list. IIndexAccessor btreeAccessor = btree.createAccessor(NoOpIndexAccessParameters.INSTANCE); try { MultiComparator btreeCmp = MultiComparator.create(btree.getComparatorFactories()); RangePredicate rangePred = new RangePredicate(null, null, true, true, btreeCmp, btreeCmp); IIndexCursor btreeCursor = btreeAccessor.createSearchCursor(false); try { btreeAccessor.search(btreeCursor, rangePred); try { doValidate(btreeCursor); } finally { btreeCursor.close(); } } finally { btreeCursor.destroy(); } } finally { btreeAccessor.destroy(); } }
IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpIndexAccessParameters.INSTANCE); try { IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false); try { indexAccessor.search(rangeCursor, rangePred);
public void checkRangeSearch(IIndexTestContext ictx, ITupleReference key) throws Exception { if (LOGGER.isInfoEnabled()) { LOGGER.info("Testing Range Search."); } AbstractRTreeTestContext ctx = (AbstractRTreeTestContext) ictx; MultiComparator cmp = RTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), key); IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false); try { SearchPredicate searchPred = new SearchPredicate(key, cmp); ctx.getIndexAccessor().search(searchCursor, searchPred); try { // Get the subset of elements from the expected set within given key // range. RTreeCheckTuple keyCheck = (RTreeCheckTuple) createCheckTupleFromTuple(key, ctx.getFieldSerdes(), cmp.getKeyFieldCount()); HashMultiSet<RTreeCheckTuple> expectedResult = null; expectedResult = getRangeSearchExpectedResults(ctx.getCheckTuples(), keyCheck); checkExpectedResults(searchCursor, expectedResult, ctx.getFieldSerdes(), ctx.getKeyFieldCount(), null); } finally { searchCursor.close(); } } finally { searchCursor.destroy(); } }
public SearchTask() throws HyracksDataException { this.cb = new SynchronizingSearchOperationCallback(); IndexAccessParameters actx = new IndexAccessParameters(NoOpOperationCallback.INSTANCE, cb); this.accessor = index.createAccessor(actx); this.cursor = accessor.createSearchCursor(false); this.predicate = new RangePredicate(); this.builder = new ArrayTupleBuilder(NUM_KEY_FIELDS); this.tuple = new ArrayTupleReference(); this.expectedTupleToBeLockedBuilder = new ArrayTupleBuilder(NUM_KEY_FIELDS); this.expectedTupleToBeLocked = new ArrayTupleReference(); this.expectedTupleToBeCanceledBuilder = new ArrayTupleBuilder(NUM_KEY_FIELDS); this.expectedTupleToBeCanceled = new ArrayTupleReference(); this.blockOnHigh = false; this.expectedAfterBlock = -1; this.expectedTupleToBeLockedValue = -1; }
IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false); try { ArrayTupleBuilder lowKeyBuilder = new ArrayTupleBuilder(ctx.getKeyFieldCount());