Search in sources :

Example 26 with MultiComparator

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

the class BTreeTestWorker method performOp.

@Override
public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException {
    BTree.BTreeAccessor accessor = (BTree.BTreeAccessor) indexAccessor;
    ITreeIndexCursor searchCursor = accessor.createSearchCursor(false);
    ITreeIndexCursor diskOrderScanCursor = accessor.createDiskOrderScanCursor();
    MultiComparator cmp = accessor.getOpContext().getCmp();
    RangePredicate rangePred = new RangePredicate(tuple, tuple, true, true, cmp, cmp);
    switch(op) {
        case INSERT:
            try {
                accessor.insert(tuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
                    // Ignore duplicate keys, since we get random tuples.
                    throw e;
                }
            }
            break;
        case DELETE:
            // Create a tuple reference with only key fields.
            deleteTb.reset();
            for (int i = 0; i < numKeyFields; i++) {
                deleteTb.addField(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
            }
            deleteTuple.reset(deleteTb.getFieldEndOffsets(), deleteTb.getByteArray());
            try {
                accessor.delete(deleteTuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
                    // Ignore non-existant keys, since we get random tuples.
                    throw e;
                }
            }
            break;
        case UPDATE:
            try {
                accessor.update(tuple);
            } catch (HyracksDataException e) {
                // Ignore non-existant keys, since we get random tuples.
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY && e.getErrorCode() != ErrorCode.INDEX_NOT_UPDATABLE) {
                    // Ignore not updateable exception due to numKeys == numFields.
                    throw e;
                }
            }
            break;
        case UPSERT:
            accessor.upsert(tuple);
            // a bigger problem and the test should fail.
            break;
        case POINT_SEARCH:
            searchCursor.reset();
            rangePred.setLowKey(tuple, true);
            rangePred.setHighKey(tuple, true);
            accessor.search(searchCursor, rangePred);
            consumeCursorTuples(searchCursor);
            break;
        case SCAN:
            searchCursor.reset();
            rangePred.setLowKey(null, true);
            rangePred.setHighKey(null, true);
            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) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

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