Search in sources :

Example 1 with ITreeIndexCursor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexCursor in project asterixdb by apache.

the class LSMRTreeWithAntiMatterTuples method createMergeOperation.

@Override
protected ILSMIOOperation createMergeOperation(AbstractLSMIndexOperationContext opCtx, List<ILSMComponent> mergingComponents, LSMComponentFileReferences mergeFileRefs, ILSMIOOperationCallback callback) throws HyracksDataException {
    boolean returnDeletedTuples = false;
    if (mergingComponents.get(mergingComponents.size() - 1) != diskComponents.get(diskComponents.size() - 1)) {
        returnDeletedTuples = true;
    }
    ITreeIndexCursor cursor = new LSMRTreeWithAntiMatterTuplesSearchCursor(opCtx, returnDeletedTuples);
    ILSMIndexAccessor accessor = new LSMTreeIndexAccessor(getLsmHarness(), opCtx, cursorFactory);
    return new MergeOperation(accessor, mergeFileRefs.getInsertIndexFileReference(), callback, fileManager.getBaseDir(), mergingComponents, cursor);
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) MergeOperation(org.apache.hyracks.storage.am.lsm.common.impls.MergeOperation) LSMTreeIndexAccessor(org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 2 with ITreeIndexCursor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexCursor in project asterixdb by apache.

the class LSMRTree method flush.

@Override
public ILSMDiskComponent flush(ILSMIOOperation operation) throws HyracksDataException {
    LSMRTreeFlushOperation flushOp = (LSMRTreeFlushOperation) operation;
    LSMRTreeMemoryComponent flushingComponent = (LSMRTreeMemoryComponent) flushOp.getFlushingComponent();
    // 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.
    // scan the memory RTree
    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(), flushOp.getBTreeTarget(), flushOp.getBloomFilterTarget(), true);
    //count the number of tuples in the buddy btree
    ITreeIndexAccessor memBTreeAccessor = flushingComponent.getBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    RangePredicate btreeNullPredicate = new RangePredicate(null, null, true, true, null, null);
    IIndexCursor btreeCountingCursor = ((BTreeAccessor) memBTreeAccessor).createCountingSearchCursor();
    memBTreeAccessor.search(btreeCountingCursor, btreeNullPredicate);
    long numBTreeTuples = 0L;
    try {
        while (btreeCountingCursor.hasNext()) {
            btreeCountingCursor.next();
            ITupleReference countTuple = btreeCountingCursor.getTuple();
            numBTreeTuples = IntegerPointable.getInteger(countTuple.getFieldData(0), countTuple.getFieldStart(0));
        }
    } finally {
        btreeCountingCursor.close();
    }
    ILSMDiskComponentBulkLoader componentBulkLoader = createComponentBulkLoader(component, 1.0f, false, numBTreeTuples, false, false);
    ITreeIndexCursor cursor;
    IBinaryComparatorFactory[] linearizerArray = { linearizer };
    TreeTupleSorter rTreeTupleSorter = new TreeTupleSorter(flushingComponent.getRTree().getFileId(), linearizerArray, rtreeLeafFrameFactory.createFrame(), rtreeLeafFrameFactory.createFrame(), flushingComponent.getRTree().getBufferCache(), comparatorFields);
    // BulkLoad the tuples from the in-memory tree into the new disk
    // RTree.
    boolean isEmpty = true;
    try {
        while (rtreeScanCursor.hasNext()) {
            isEmpty = false;
            rtreeScanCursor.next();
            rTreeTupleSorter.insertTupleEntry(rtreeScanCursor.getPageId(), rtreeScanCursor.getTupleOffset());
        }
    } finally {
        rtreeScanCursor.close();
    }
    rTreeTupleSorter.sort();
    cursor = rTreeTupleSorter;
    if (!isEmpty) {
        try {
            while (cursor.hasNext()) {
                cursor.next();
                ITupleReference frameTuple = cursor.getTuple();
                componentBulkLoader.add(frameTuple);
            }
        } finally {
            cursor.close();
        }
    }
    // scan the memory BTree
    IIndexCursor btreeScanCursor = memBTreeAccessor.createSearchCursor(false);
    memBTreeAccessor.search(btreeScanCursor, btreeNullPredicate);
    try {
        while (btreeScanCursor.hasNext()) {
            btreeScanCursor.next();
            ITupleReference frameTuple = btreeScanCursor.getTuple();
            componentBulkLoader.delete(frameTuple);
        }
    } finally {
        btreeScanCursor.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());
    }
    // Note. If we change the filter to write to metadata object, we don't need the if block above
    flushingComponent.getMetadata().copy(component.getMetadata());
    componentBulkLoader.end();
    return component;
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) ArrayList(java.util.ArrayList) BTreeAccessor(org.apache.hyracks.storage.am.btree.impls.BTree.BTreeAccessor) 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) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor)

Example 3 with ITreeIndexCursor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexCursor in project asterixdb by apache.

the class OrderedIndexExamplesTest method rangeSearch.

protected void rangeSearch(IBinaryComparatorFactory[] cmpFactories, IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes, ITupleReference lowKey, ITupleReference highKey, ITupleReference minFilterTuple, ITupleReference maxFilterTuple) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        String lowKeyString = TupleUtils.printTuple(lowKey, fieldSerdes);
        String highKeyString = TupleUtils.printTuple(highKey, fieldSerdes);
        LOGGER.info("Range-Search in: [ " + lowKeyString + ", " + highKeyString + "]");
    }
    ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
    MultiComparator lowKeySearchCmp = BTreeUtils.getSearchMultiComparator(cmpFactories, lowKey);
    MultiComparator highKeySearchCmp = BTreeUtils.getSearchMultiComparator(cmpFactories, highKey);
    RangePredicate rangePred;
    if (minFilterTuple != null && maxFilterTuple != null) {
        rangePred = new RangePredicate(lowKey, highKey, true, true, lowKeySearchCmp, highKeySearchCmp, minFilterTuple, maxFilterTuple);
    } else {
        rangePred = new RangePredicate(lowKey, highKey, true, true, lowKeySearchCmp, highKeySearchCmp);
    }
    indexAccessor.search(rangeCursor, rangePred);
    try {
        while (rangeCursor.hasNext()) {
            rangeCursor.next();
            ITupleReference frameTuple = rangeCursor.getTuple();
            String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(rec);
            }
        }
    } finally {
        rangeCursor.close();
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 4 with ITreeIndexCursor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexCursor in project asterixdb by apache.

the class AbstractRTreeExamplesTest method rangeSearch.

protected void rangeSearch(IBinaryComparatorFactory[] cmpFactories, IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes, ITupleReference key, ITupleReference minFilterTuple, ITupleReference maxFilterTuple) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        String kString = TupleUtils.printTuple(key, fieldSerdes);
        LOGGER.info("Range-Search using key: " + kString);
    }
    ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
    MultiComparator cmp = RTreeUtils.getSearchMultiComparator(cmpFactories, key);
    SearchPredicate rangePred;
    if (minFilterTuple != null && maxFilterTuple != null) {
        rangePred = new SearchPredicate(key, cmp, minFilterTuple, maxFilterTuple);
    } else {
        rangePred = new SearchPredicate(key, cmp);
    }
    indexAccessor.search(rangeCursor, rangePred);
    try {
        while (rangeCursor.hasNext()) {
            rangeCursor.next();
            ITupleReference frameTuple = rangeCursor.getTuple();
            String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(rec);
            }
        }
    } finally {
        rangeCursor.close();
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)

Example 5 with ITreeIndexCursor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexCursor 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)

Aggregations

ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)23 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)10 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)9 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)8 SearchPredicate (org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)8 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)7 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)6 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)6 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)4 LSMTreeIndexAccessor (org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor)4 ArrayList (java.util.ArrayList)3 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)3 BTree (org.apache.hyracks.storage.am.btree.impls.BTree)3 AMutableString (org.apache.asterix.om.base.AMutableString)2 AString (org.apache.asterix.om.base.AString)2 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)2 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)2 BTreeRangeSearchCursor (org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor)2 IMetadataPageManager (org.apache.hyracks.storage.am.common.api.IMetadataPageManager)2