Search in sources :

Example 41 with ITupleReference

use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference 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 42 with ITupleReference

use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.

the class RTreeTestUtils method checkExpectedResults.

@Override
public void checkExpectedResults(ITreeIndexCursor cursor, Collection checkTuples, ISerializerDeserializer[] fieldSerdes, int keyFieldCount, Iterator<CheckTuple> checkIter) throws Exception {
    int actualCount = 0;
    try {
        while (cursor.hasNext()) {
            cursor.next();
            ITupleReference tuple = cursor.getTuple();
            RTreeCheckTuple checkTuple = (RTreeCheckTuple) createCheckTupleFromTuple(tuple, fieldSerdes, keyFieldCount);
            if (!checkTuples.contains(checkTuple)) {
                fail("Scan or range search returned unexpected answer: " + checkTuple.toString());
            }
            actualCount++;
        }
        if (actualCount < checkTuples.size()) {
            fail("Scan or range search returned fewer answers than expected.\nExpected: " + checkTuples.size() + "\nActual  : " + actualCount);
        }
        if (actualCount > checkTuples.size()) {
            fail("Scan or range search returned more answers than expected.\nExpected: " + checkTuples.size() + "\nActual  : " + actualCount);
        }
    } finally {
        cursor.close();
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 43 with ITupleReference

use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.

the class OrderedIndexTestDriver method oneStringKeyAndValue.

@Test
public void oneStringKeyAndValue() throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("BTree " + getTestOpName() + " Test With One String Key And Value.");
    }
    ISerializerDeserializer[] fieldSerdes = { new UTF8StringSerializerDeserializer(), new UTF8StringSerializerDeserializer() };
    // Range search in ["cbf", cc7"]
    ITupleReference lowKey = TupleUtils.createTuple(fieldSerdes, "cbf");
    ITupleReference highKey = TupleUtils.createTuple(fieldSerdes, "cc7");
    for (BTreeLeafFrameType leafFrameType : leafFrameTypesToTest) {
        runTest(fieldSerdes, 1, leafFrameType, lowKey, highKey, null, null);
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) UTF8StringSerializerDeserializer(org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) BTreeLeafFrameType(org.apache.hyracks.storage.am.btree.frames.BTreeLeafFrameType) Test(org.junit.Test)

Example 44 with ITupleReference

use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.

the class OrderedIndexTestUtils method checkExpectedResults.

@Override
public void checkExpectedResults(ITreeIndexCursor cursor, Collection checkTuples, ISerializerDeserializer[] fieldSerdes, int keyFieldCount, Iterator<CheckTuple> checkIter) throws Exception {
    int actualCount = 0;
    try {
        while (cursor.hasNext()) {
            if (!checkIter.hasNext()) {
                fail("Ordered scan returned more answers than expected.\nExpected: " + checkTuples.size());
            }
            cursor.next();
            CheckTuple expectedTuple = checkIter.next();
            ITupleReference tuple = cursor.getTuple();
            compareActualAndExpected(tuple, expectedTuple, fieldSerdes);
            actualCount++;
        }
        if (actualCount < checkTuples.size()) {
            fail("Ordered scan returned fewer answers than expected.\nExpected: " + checkTuples.size() + "\nActual  : " + actualCount);
        }
    } finally {
        cursor.close();
    }
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 45 with ITupleReference

use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.

the class OrderedIndexTestUtils method checkPointSearches.

public void checkPointSearches(IIndexTestContext ictx) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Testing Point Searches On All Expected Keys.");
    }
    OrderedIndexTestContext ctx = (OrderedIndexTestContext) ictx;
    IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false);
    ArrayTupleBuilder lowKeyBuilder = new ArrayTupleBuilder(ctx.getKeyFieldCount());
    ArrayTupleReference lowKey = new ArrayTupleReference();
    ArrayTupleBuilder highKeyBuilder = new ArrayTupleBuilder(ctx.getKeyFieldCount());
    ArrayTupleReference highKey = new ArrayTupleReference();
    RangePredicate rangePred = new RangePredicate(lowKey, highKey, true, true, null, null);
    // BTree to verify the tuple can be reached.
    for (CheckTuple checkTuple : ctx.getCheckTuples()) {
        createTupleFromCheckTuple(checkTuple, lowKeyBuilder, lowKey, ctx.getFieldSerdes());
        createTupleFromCheckTuple(checkTuple, highKeyBuilder, highKey, ctx.getFieldSerdes());
        MultiComparator lowKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), lowKey);
        MultiComparator highKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), highKey);
        rangePred.setLowKey(lowKey, true);
        rangePred.setHighKey(highKey, true);
        rangePred.setLowKeyComparator(lowKeyCmp);
        rangePred.setHighKeyComparator(highKeyCmp);
        ctx.getIndexAccessor().search(searchCursor, rangePred);
        try {
            // We expect exactly one answer.
            if (searchCursor.hasNext()) {
                searchCursor.next();
                ITupleReference tuple = searchCursor.getTuple();
                compareActualAndExpected(tuple, checkTuple, ctx.getFieldSerdes());
            }
            if (searchCursor.hasNext()) {
                fail("Point search returned more than one answer.");
            }
        } finally {
            searchCursor.close();
        }
    }
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) ArrayTupleReference(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)

Aggregations

ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)149 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)80 ArrayList (java.util.ArrayList)40 ACIDException (org.apache.asterix.common.exceptions.ACIDException)31 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)26 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)20 Test (org.junit.Test)20 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)18 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)18 Dataset (org.apache.asterix.metadata.entities.Dataset)10 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)10 CheckTuple (org.apache.hyracks.storage.am.common.CheckTuple)8 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)8 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)8 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)7 ILSMDiskComponentBulkLoader (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader)7 SearchPredicate (org.apache.hyracks.storage.am.rtree.impls.SearchPredicate)7 ExtensionMetadataDataset (org.apache.asterix.metadata.api.ExtensionMetadataDataset)6 Datatype (org.apache.asterix.metadata.entities.Datatype)6 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)6