Search in sources :

Example 6 with SearchPredicate

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);
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)

Example 7 with SearchPredicate

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.");
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) LSMRTreeAccessor(org.apache.hyracks.storage.am.lsm.rtree.impls.LSMRTreeAccessor) LSMRTreeOpContext(org.apache.hyracks.storage.am.lsm.rtree.impls.LSMRTreeOpContext) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 8 with SearchPredicate

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.");
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) RTree(org.apache.hyracks.storage.am.rtree.impls.RTree) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 9 with SearchPredicate

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;
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) ArrayList(java.util.ArrayList) ILSMDiskComponentBulkLoader(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader) RTreeSearchCursor(org.apache.hyracks.storage.am.rtree.impls.RTreeSearchCursor) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 10 with SearchPredicate

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();
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)

Aggregations

SearchPredicate (org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)13 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)8 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)7 ISearchPredicate (org.apache.hyracks.storage.common.ISearchPredicate)7 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)6 ArrayList (java.util.ArrayList)5 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)5 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 ILSMDiskComponentBulkLoader (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader)4 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)3 ILSMIndexOperationContext (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext)3 RTreeSearchCursor (org.apache.hyracks.storage.am.rtree.impls.RTreeSearchCursor)3 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)2 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)2 LSMRTreeOpContext (org.apache.hyracks.storage.am.lsm.rtree.impls.LSMRTreeOpContext)2 RTree (org.apache.hyracks.storage.am.rtree.impls.RTree)2 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)1