Search in sources :

Example 21 with ITreeIndexCursor

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

Example 22 with ITreeIndexCursor

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

the class TreeIndexTestUtils method checkDiskOrderScan.

public void checkDiskOrderScan(IIndexTestContext ctx) throws Exception {
    try {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Testing Disk-Order Scan.");
        }
        ITreeIndexAccessor treeIndexAccessor = (ITreeIndexAccessor) ctx.getIndexAccessor();
        ITreeIndexCursor diskOrderCursor = treeIndexAccessor.createDiskOrderScanCursor();
        treeIndexAccessor.diskOrderScan(diskOrderCursor);
        int actualCount = 0;
        try {
            while (diskOrderCursor.hasNext()) {
                diskOrderCursor.next();
                ITupleReference tuple = diskOrderCursor.getTuple();
                CheckTuple checkTuple = createCheckTupleFromTuple(tuple, ctx.getFieldSerdes(), ctx.getKeyFieldCount());
                if (!checkDiskOrderScanResult(tuple, checkTuple, ctx)) {
                    fail("Disk-order scan returned unexpected answer: " + checkTuple.toString());
                }
                actualCount++;
            }
            if (actualCount < ctx.getCheckTuples().size()) {
                fail("Disk-order scan returned fewer answers than expected.\nExpected: " + ctx.getCheckTuples().size() + "\nActual  : " + actualCount);
            }
            if (actualCount > ctx.getCheckTuples().size()) {
                fail("Disk-order scan returned more answers than expected.\nExpected: " + ctx.getCheckTuples().size() + "\nActual  : " + actualCount);
            }
        } finally {
            try {
                diskOrderCursor.close();
            } catch (Exception ex) {
                LOGGER.log(Level.WARNING, "Error during scan cursor close", ex);
            }
        }
    } catch (UnsupportedOperationException e) {
        // support disk-order scan.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    } catch (ClassCastException e) {
        // an ITreeIndexAccessor, e.g., for the LSMBTree.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 23 with ITreeIndexCursor

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

the class TreeIndexTestUtils method checkScan.

@SuppressWarnings("unchecked")
public void checkScan(IIndexTestContext ctx) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Testing Scan.");
    }
    ITreeIndexCursor scanCursor = (ITreeIndexCursor) ctx.getIndexAccessor().createSearchCursor(false);
    ISearchPredicate nullPred = createNullSearchPredicate();
    ctx.getIndexAccessor().search(scanCursor, nullPred);
    Iterator<CheckTuple> checkIter = ctx.getCheckTuples().iterator();
    checkExpectedResults(scanCursor, ctx.getCheckTuples(), ctx.getFieldSerdes(), ctx.getKeyFieldCount(), checkIter);
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate)

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