Search in sources :

Example 16 with MultiComparator

use of org.apache.hyracks.storage.common.MultiComparator in project asterixdb by apache.

the class RTree method printTree.

@SuppressWarnings("rawtypes")
public String printTree(IRTreeLeafFrame leafFrame, IRTreeInteriorFrame interiorFrame, ISerializerDeserializer[] keySerdes) throws Exception {
    MultiComparator cmp = MultiComparator.create(cmpFactories);
    byte treeHeight = getTreeHeight(leafFrame);
    StringBuilder strBuilder = new StringBuilder();
    printTree(rootPage, null, false, leafFrame, interiorFrame, treeHeight, keySerdes, strBuilder, cmp);
    return strBuilder.toString();
}
Also used : MultiComparator(org.apache.hyracks.storage.common.MultiComparator)

Example 17 with MultiComparator

use of org.apache.hyracks.storage.common.MultiComparator in project asterixdb by apache.

the class OrderedIndexTestUtils method checkRangeSearch.

@SuppressWarnings("unchecked")
public void checkRangeSearch(IIndexTestContext ctx, ITupleReference lowKey, ITupleReference highKey, boolean lowKeyInclusive, boolean highKeyInclusive) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Testing Range Search.");
    }
    MultiComparator lowKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), lowKey);
    MultiComparator highKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), highKey);
    IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false);
    RangePredicate rangePred = new RangePredicate(lowKey, highKey, lowKeyInclusive, highKeyInclusive, lowKeyCmp, highKeyCmp);
    ctx.getIndexAccessor().search(searchCursor, rangePred);
    // Get the subset of elements from the expected set within given key
    // range.
    CheckTuple lowKeyCheck = createCheckTupleFromTuple(lowKey, ctx.getFieldSerdes(), lowKeyCmp.getKeyFieldCount());
    CheckTuple highKeyCheck = createCheckTupleFromTuple(highKey, ctx.getFieldSerdes(), highKeyCmp.getKeyFieldCount());
    SortedSet<CheckTuple> expectedSubset = null;
    if (lowKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount() || highKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount()) {
        // Searching on a key prefix (low key or high key or both).
        expectedSubset = getPrefixExpectedSubset((TreeSet<CheckTuple>) ctx.getCheckTuples(), lowKeyCheck, highKeyCheck);
    } else {
        // Searching on all key fields.
        expectedSubset = ((TreeSet<CheckTuple>) ctx.getCheckTuples()).subSet(lowKeyCheck, lowKeyInclusive, highKeyCheck, highKeyInclusive);
    }
    Iterator<CheckTuple> checkIter = expectedSubset.iterator();
    int actualCount = 0;
    try {
        while (searchCursor.hasNext()) {
            if (!checkIter.hasNext()) {
                fail("Range search returned more answers than expected.\nExpected: " + expectedSubset.size());
            }
            searchCursor.next();
            CheckTuple expectedTuple = checkIter.next();
            ITupleReference tuple = searchCursor.getTuple();
            compareActualAndExpected(tuple, expectedTuple, ctx.getFieldSerdes());
            actualCount++;
        }
        if (actualCount < expectedSubset.size()) {
            fail("Range search returned fewer answers than expected.\nExpected: " + expectedSubset.size() + "\nActual  : " + actualCount);
        }
    } finally {
        searchCursor.close();
    }
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) TreeSet(java.util.TreeSet) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor)

Example 18 with MultiComparator

use of org.apache.hyracks.storage.common.MultiComparator in project asterixdb by apache.

the class MetadataNode method searchIndex.

private <ResultType> void searchIndex(JobId jobId, IMetadataIndex index, ITupleReference searchKey, IValueExtractor<ResultType> valueExtractor, List<ResultType> results) throws MetadataException, HyracksDataException, RemoteException {
    IBinaryComparatorFactory[] comparatorFactories = index.getKeyBinaryComparatorFactory();
    if (index.getFile() == null) {
        throw new MetadataException("No file for Index " + index.getDataverseName() + "." + index.getIndexName());
    }
    String resourceName = index.getFile().getRelativePath();
    IIndex indexInstance = datasetLifecycleManager.get(resourceName);
    datasetLifecycleManager.open(resourceName);
    IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
    IBinaryComparator[] searchCmps = null;
    MultiComparator searchCmp = null;
    RangePredicate rangePred = null;
    if (searchKey != null) {
        searchCmps = new IBinaryComparator[searchKey.getFieldCount()];
        for (int i = 0; i < searchKey.getFieldCount(); i++) {
            searchCmps[i] = comparatorFactories[i].createBinaryComparator();
        }
        searchCmp = new MultiComparator(searchCmps);
    }
    rangePred = new RangePredicate(searchKey, searchKey, true, true, searchCmp, searchCmp);
    indexAccessor.search(rangeCursor, rangePred);
    try {
        while (rangeCursor.hasNext()) {
            rangeCursor.next();
            ResultType result = valueExtractor.getValue(jobId, rangeCursor.getTuple());
            if (result != null) {
                results.add(result);
            }
        }
    } finally {
        rangeCursor.close();
    }
    datasetLifecycleManager.close(resourceName);
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) 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) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Example 19 with MultiComparator

use of org.apache.hyracks.storage.common.MultiComparator in project asterixdb by apache.

the class LSMInvertedIndex method createCursorInitialState.

private ICursorInitialState createCursorInitialState(ISearchPredicate pred, IIndexOperationContext ictx, boolean includeMutableComponent, ArrayList<IIndexAccessor> indexAccessors, ArrayList<IIndexAccessor> deletedKeysBTreeAccessors, List<ILSMComponent> operationalComponents) {
    ICursorInitialState initState;
    PermutingTupleReference keysOnlyTuple = createKeysOnlyTupleReference();
    MultiComparator keyCmp = MultiComparator.create(invListCmpFactories);
    // Distinguish between regular searches and range searches (mostly used in merges).
    if (pred instanceof InvertedIndexSearchPredicate) {
        initState = new LSMInvertedIndexSearchCursorInitialState(keyCmp, keysOnlyTuple, indexAccessors, deletedKeysBTreeAccessors, ((LSMInvertedIndexMemoryComponent) memoryComponents.get(currentMutableComponentId.get())).getDeletedKeysBTree().getLeafFrameFactory(), ictx, includeMutableComponent, getLsmHarness(), operationalComponents);
    } else {
        LSMInvertedIndexMemoryComponent mutableComponent = (LSMInvertedIndexMemoryComponent) memoryComponents.get(currentMutableComponentId.get());
        InMemoryInvertedIndex memInvIndex = (InMemoryInvertedIndex) mutableComponent.getInvIndex();
        MultiComparator tokensAndKeysCmp = MultiComparator.create(memInvIndex.getBTree().getComparatorFactories());
        initState = new LSMInvertedIndexRangeSearchCursorInitialState(tokensAndKeysCmp, keyCmp, keysOnlyTuple, ((LSMInvertedIndexMemoryComponent) memoryComponents.get(currentMutableComponentId.get())).getDeletedKeysBTree().getLeafFrameFactory(), includeMutableComponent, getLsmHarness(), indexAccessors, deletedKeysBTreeAccessors, pred, operationalComponents);
    }
    return initState;
}
Also used : PermutingTupleReference(org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference) ICursorInitialState(org.apache.hyracks.storage.common.ICursorInitialState) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) InvertedIndexSearchPredicate(org.apache.hyracks.storage.am.lsm.invertedindex.search.InvertedIndexSearchPredicate) InMemoryInvertedIndex(org.apache.hyracks.storage.am.lsm.invertedindex.inmemory.InMemoryInvertedIndex)

Example 20 with MultiComparator

use of org.apache.hyracks.storage.common.MultiComparator in project asterixdb by apache.

the class LSMInvertedIndexSearchCursor method open.

@Override
public void open(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();
    // For searching the deleted-keys BTrees.
    deletedKeysBTreeAccessors = lsmInitState.getDeletedKeysBTreeAccessors();
    deletedKeysBTreeCursors = new IIndexCursor[deletedKeysBTreeAccessors.size()];
    for (int i = 0; i < operationalComponents.size(); i++) {
        ILSMComponent component = operationalComponents.get(i);
        if (component.getType() == LSMComponentType.MEMORY) {
            // No need for a bloom filter for the in-memory BTree.
            deletedKeysBTreeCursors[i] = deletedKeysBTreeAccessors.get(i).createSearchCursor(false);
        } else {
            deletedKeysBTreeCursors[i] = new BloomFilterAwareBTreePointSearchCursor((IBTreeLeafFrame) lsmInitState.getgetDeletedKeysBTreeLeafFrameFactory().createFrame(), false, ((LSMInvertedIndexDiskComponent) operationalComponents.get(i)).getBloomFilter());
        }
    }
    MultiComparator keyCmp = lsmInitState.getKeyComparator();
    keySearchPred = new RangePredicate(null, null, true, true, keyCmp, keyCmp);
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BloomFilterAwareBTreePointSearchCursor(org.apache.hyracks.storage.am.lsm.common.impls.BloomFilterAwareBTreePointSearchCursor)

Aggregations

MultiComparator (org.apache.hyracks.storage.common.MultiComparator)26 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)13 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)10 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)9 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)9 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)6 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)6 SearchPredicate (org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)6 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)5 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)4 CheckTuple (org.apache.hyracks.storage.am.common.CheckTuple)4 IInvertedIndexAccessor (org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndexAccessor)4 IBinaryComparator (org.apache.hyracks.api.dataflow.value.IBinaryComparator)3 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)3 PermutingTupleReference (org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference)3 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)3 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)2 IBTreeLeafFrame (org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame)2 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)2 BloomFilterAwareBTreePointSearchCursor (org.apache.hyracks.storage.am.lsm.common.impls.BloomFilterAwareBTreePointSearchCursor)2