@Override public void doOpen(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException { this.btreePred = (RangePredicate) searchPred; btreeAccessor.search(btreeCursor, btreePred); openInvListRangeSearchCursor(); }
protected void open(IIndexAccessor accessor, IIndexCursor cursor, ISearchPredicate predicate) throws HyracksDataException { accessor.search(cursor, predicate); }
public static void open(List<IIndexAccessor> accessors, IIndexCursor[] cursors, ISearchPredicate pred) throws HyracksDataException { int opened = 0; try { for (int i = 0; i < cursors.length; i++) { if (accessors.get(i) != null) { accessors.get(i).search(cursors[i], pred); } opened++; } } catch (Throwable th) { // NOSONAR: Much catch all failures for (int j = 0; j < opened; j++) { IndexCursorUtils.close(cursors[j], th); } throw HyracksDataException.create(th); } }
public static void open(IIndexAccessor[] accessors, IIndexCursor[] cursors, ISearchPredicate pred) throws HyracksDataException { int opened = 0; try { for (int i = 0; i < accessors.length; i++) { if (accessors[i] != null) { accessors[i].search(cursors[i], pred); } opened++; } } catch (Throwable th) { // NOSONAR: Much catch all failures for (int j = 0; j < opened; j++) { IndexCursorUtils.close(cursors[j], th); } throw HyracksDataException.create(th); } }
@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; } }
protected boolean isDeleted(ITupleReference key) throws HyracksDataException { keySearchPred.setLowKey(key, true); keySearchPred.setHighKey(key, true); for (int i = 0; i < accessorIndex; i++) { deletedKeysBTreeCursors[i].close(); if (deletedKeysBTreeBloomFilters[i] != null && !deletedKeysBTreeBloomFilters[i].contains(key, hashes)) { continue; } try { deletedKeysBTreeAccessors.get(i).search(deletedKeysBTreeCursors[i], keySearchPred); if (deletedKeysBTreeCursors[i].hasNext()) { return true; } } finally { deletedKeysBTreeCursors[i].close(); } } return false; }
/** * Check deleted-keys BTrees whether they contain the key in the checkElement's tuple. */ protected boolean isDeleted(PriorityQueueElement keyElement) throws HyracksDataException { ITupleReference keyTuple = keyElement.getTuple(); int end = keyElement.getCursorIndex(); for (int i = 0; i < end; i++) { if (bloomFilters[i] != null && !bloomFilters[i].contains(keyTuple, hashes)) { continue; } deletedKeysBTreeCursors[i].close(); deletedKeysBTreeAccessors.get(i).search(deletedKeysBTreeCursors[i], deletedKeyBTreeSearchPred); try { if (deletedKeysBTreeCursors[i].hasNext()) { return true; } } finally { deletedKeysBTreeCursors[i].close(); } } return false; }
/** * Check deleted-keys BTrees whether they contain the key in the checkElement's tuple. */ @Override protected boolean isDeleted(PriorityQueueElement checkElement) throws HyracksDataException { keysOnlyTuple.reset(checkElement.getTuple()); int end = checkElement.getCursorIndex(); for (int i = 0; i < end; i++) { if (bloomFilters[i] != null && !bloomFilters[i].contains(keysOnlyTuple, hashes)) { continue; } deletedKeysBTreeAccessors.get(i).search(deletedKeysBTreeCursors[i], keySearchPred); try { if (deletedKeysBTreeCursors[i].hasNext()) { return true; } } finally { deletedKeysBTreeCursors[i].close(); } } return false; }
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(); } }
@Override public void nextFrame(ByteBuffer buffer) throws HyracksDataException { accessor.reset(buffer); int tupleCount = accessor.getTupleCount(); try { for (int i = 0; i < tupleCount && !finished; i++) { resetSearchPredicate(i); cursor.close(); indexAccessor.search(cursor, searchPred); writeSearchResults(i); } } catch (Exception e) { throw HyracksDataException.create(e); } }
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(); } }
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(); } }
@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(); } }
@Override public void doOpen(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException { LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState; cmp = lsmInitialState.getBTreeCmp(); 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 r-trees. lsmHarness = null; int numBTrees = operationalComponents.size(); rangeCursors = new IIndexCursor[numBTrees]; RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp); IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees]; for (int i = 0; i < numBTrees; i++) { ILSMComponent component = operationalComponents.get(i); IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame(); rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false); BTree btree = ((LSMRTreeDiskComponent) component).getBuddyIndex(); btreeAccessors[i] = btree.createAccessor(NoOpIndexAccessParameters.INSTANCE); btreeAccessors[i].search(rangeCursors[i], btreePredicate); } IndexCursorUtils.open(btreeAccessors, rangeCursors, btreePredicate); try { setPriorityQueueComparator(); initPriorityQueue(); } catch (Throwable th) { // NOSONAR: Must catch all failures IndexCursorUtils.close(rangeCursors, th); throw HyracksDataException.create(th); } } }
@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(); } }
predicate.setLowKey(tuple, true); predicate.setHighKey(null, true); accessor.search(cursor, predicate); try { expectedTupleToBeLockedValue = 50;
IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false); try { indexAccessor.search(rangeCursor, rangePred); try { while (rangeCursor.hasNext()) {
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(); } }
@Override public void openInvertedListCursor(InvertedListCursor listCursor, ITupleReference searchKey, IIndexOperationContext ictx) throws HyracksDataException { OnDiskInvertedIndexOpContext ctx = (OnDiskInvertedIndexOpContext) ictx; ctx.getBtreePred().setLowKeyComparator(ctx.getSearchCmp()); ctx.getBtreePred().setHighKeyComparator(ctx.getSearchCmp()); ctx.getBtreePred().setLowKey(searchKey, true); ctx.getBtreePred().setHighKey(searchKey, true); ctx.getBtreeAccessor().search(ctx.getBtreeCursor(), ctx.getBtreePred()); try { if (ctx.getBtreeCursor().hasNext()) { ctx.getBtreeCursor().next(); openInvertedListCursor(ctx.getBtreeCursor().getTuple(), listCursor, ctx); } else { LSMInvertedIndexSearchCursorInitialState initState = ctx.getCursorInitialState(); initState.setInvertedListInfo(0, 0, 0, 0); listCursor.open(initState, null); } } finally { ctx.getBtreeCursor().close(); } }