use of org.apache.hyracks.storage.am.rtree.impls.SearchPredicate in project asterixdb by apache.
the class RTreeTestUtils method checkRangeSearch.
public void checkRangeSearch(IIndexTestContext ictx, ITupleReference key) throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Testing Range Search.");
}
AbstractRTreeTestContext ctx = (AbstractRTreeTestContext) ictx;
MultiComparator cmp = RTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), key);
ITreeIndexCursor searchCursor = (ITreeIndexCursor) ctx.getIndexAccessor().createSearchCursor(false);
SearchPredicate searchPred = new SearchPredicate(key, cmp);
ctx.getIndexAccessor().search(searchCursor, searchPred);
// 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);
}
use of org.apache.hyracks.storage.am.rtree.impls.SearchPredicate in project asterixdb by apache.
the class LSMRTreeTestWorker method performOp.
@Override
public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException {
LSMRTreeAccessor accessor = (LSMRTreeAccessor) indexAccessor;
ITreeIndexCursor searchCursor = accessor.createSearchCursor(false);
LSMRTreeOpContext concreteCtx = (LSMRTreeOpContext) accessor.getCtx();
MultiComparator cmp = concreteCtx.getCurrentRTreeOpContext().getCmp();
SearchPredicate rangePred = new SearchPredicate(tuple, cmp);
switch(op) {
case INSERT:
rearrangeTuple(tuple, cmp);
accessor.insert(rearrangedTuple);
break;
case DELETE:
rearrangeTuple(tuple, cmp);
accessor.delete(rearrangedTuple);
break;
case SCAN:
searchCursor.reset();
rangePred.setSearchKey(null);
accessor.search(searchCursor, rangePred);
consumeCursorTuples(searchCursor);
break;
case MERGE:
accessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), lsmRTree.getImmutableComponents());
break;
default:
throw new HyracksDataException("Op " + op.toString() + " not supported.");
}
}
use of org.apache.hyracks.storage.am.rtree.impls.SearchPredicate in project asterixdb by apache.
the class RTreeTestWorker method performOp.
@Override
public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException {
RTree.RTreeAccessor accessor = (RTree.RTreeAccessor) indexAccessor;
IIndexCursor searchCursor = accessor.createSearchCursor(false);
ITreeIndexCursor diskOrderScanCursor = accessor.createDiskOrderScanCursor();
MultiComparator cmp = accessor.getOpContext().getCmp();
SearchPredicate rangePred = new SearchPredicate(tuple, cmp);
switch(op) {
case INSERT:
rearrangeTuple(tuple, cmp);
accessor.insert(rearrangedTuple);
break;
case DELETE:
rearrangeTuple(tuple, cmp);
accessor.delete(rearrangedTuple);
break;
case SCAN:
searchCursor.reset();
rangePred.setSearchKey(null);
accessor.search(searchCursor, rangePred);
consumeCursorTuples(searchCursor);
break;
case DISKORDER_SCAN:
diskOrderScanCursor.reset();
accessor.diskOrderScan(diskOrderScanCursor);
consumeCursorTuples(diskOrderScanCursor);
break;
default:
throw new HyracksDataException("Op " + op.toString() + " not supported.");
}
}
use of org.apache.hyracks.storage.am.rtree.impls.SearchPredicate in project asterixdb by apache.
the class LSMRTreeWithAntiMatterTuples method flush.
@Override
public ILSMDiskComponent flush(ILSMIOOperation operation) throws HyracksDataException {
LSMRTreeFlushOperation flushOp = (LSMRTreeFlushOperation) operation;
// Renaming order is critical because we use assume ordering when we
// read the file names when we open the tree.
// The RTree should be renamed before the BTree.
LSMRTreeMemoryComponent flushingComponent = (LSMRTreeMemoryComponent) flushOp.getFlushingComponent();
ITreeIndexAccessor memRTreeAccessor = flushingComponent.getRTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
RTreeSearchCursor rtreeScanCursor = (RTreeSearchCursor) memRTreeAccessor.createSearchCursor(false);
SearchPredicate rtreeNullPredicate = new SearchPredicate(null, null);
memRTreeAccessor.search(rtreeScanCursor, rtreeNullPredicate);
LSMRTreeDiskComponent component = createDiskComponent(componentFactory, flushOp.getTarget(), null, null, true);
ILSMDiskComponentBulkLoader componentBulkLoader = createComponentBulkLoader(component, 1.0f, false, 0L, false, false);
// Since the LSM-RTree is used as a secondary assumption, the
// primary key will be the last comparator in the BTree comparators
TreeTupleSorter rTreeTupleSorter = new TreeTupleSorter(flushingComponent.getRTree().getFileId(), linearizerArray, rtreeLeafFrameFactory.createFrame(), rtreeLeafFrameFactory.createFrame(), flushingComponent.getRTree().getBufferCache(), comparatorFields);
boolean isEmpty = true;
try {
while (rtreeScanCursor.hasNext()) {
isEmpty = false;
rtreeScanCursor.next();
rTreeTupleSorter.insertTupleEntry(rtreeScanCursor.getPageId(), rtreeScanCursor.getTupleOffset());
}
} finally {
rtreeScanCursor.close();
}
if (!isEmpty) {
rTreeTupleSorter.sort();
}
// scan the memory BTree
ITreeIndexAccessor memBTreeAccessor = flushingComponent.getBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
BTreeRangeSearchCursor btreeScanCursor = (BTreeRangeSearchCursor) memBTreeAccessor.createSearchCursor(false);
RangePredicate btreeNullPredicate = new RangePredicate(null, null, true, true, null, null);
memBTreeAccessor.search(btreeScanCursor, btreeNullPredicate);
TreeTupleSorter bTreeTupleSorter = new TreeTupleSorter(flushingComponent.getBTree().getFileId(), linearizerArray, btreeLeafFrameFactory.createFrame(), btreeLeafFrameFactory.createFrame(), flushingComponent.getBTree().getBufferCache(), comparatorFields);
isEmpty = true;
try {
while (btreeScanCursor.hasNext()) {
isEmpty = false;
btreeScanCursor.next();
bTreeTupleSorter.insertTupleEntry(btreeScanCursor.getPageId(), btreeScanCursor.getTupleOffset());
}
} finally {
btreeScanCursor.close();
}
if (!isEmpty) {
bTreeTupleSorter.sort();
}
LSMRTreeWithAntiMatterTuplesFlushCursor cursor = new LSMRTreeWithAntiMatterTuplesFlushCursor(rTreeTupleSorter, bTreeTupleSorter, comparatorFields, linearizerArray);
cursor.open(null, null);
try {
while (cursor.hasNext()) {
cursor.next();
ITupleReference frameTuple = cursor.getTuple();
componentBulkLoader.add(frameTuple);
}
} finally {
cursor.close();
}
if (component.getLSMComponentFilter() != null) {
List<ITupleReference> filterTuples = new ArrayList<>();
filterTuples.add(flushingComponent.getLSMComponentFilter().getMinTuple());
filterTuples.add(flushingComponent.getLSMComponentFilter().getMaxTuple());
getFilterManager().updateFilter(component.getLSMComponentFilter(), filterTuples);
getFilterManager().writeFilter(component.getLSMComponentFilter(), component.getRTree());
}
flushingComponent.getMetadata().copy(component.getMetadata());
componentBulkLoader.end();
return component;
}
use of org.apache.hyracks.storage.am.rtree.impls.SearchPredicate in project asterixdb by apache.
the class AbstractRTreeExamplesTest method scan.
protected void scan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Scan:");
}
ITreeIndexCursor scanCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
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.isLoggable(Level.INFO)) {
LOGGER.info(rec);
}
}
} finally {
scanCursor.close();
}
}
Aggregations