コード例 #1
0
  @Override
  public void open(ICursorInitialState initialState, ISearchPredicate searchPred)
      throws HyracksDataException, IndexException {
    LSMBTreeCursorInitialState lsmInitialState = (LSMBTreeCursorInitialState) initialState;
    cmp = lsmInitialState.getOriginalKeyComparator();
    includeMemComponent = lsmInitialState.getIncludeMemComponent();
    operationalComponents = lsmInitialState.getOperationalComponents();
    lsmHarness = lsmInitialState.getLSMHarness();
    searchCallback = lsmInitialState.getSearchOperationCallback();
    memBTreeAccessor = lsmInitialState.getMemBTreeAccessor();
    predicate = (RangePredicate) lsmInitialState.getSearchPredicate();
    reusablePred.setLowKeyComparator(cmp);
    reusablePred.setHighKey(predicate.getHighKey(), predicate.isHighKeyInclusive());
    reusablePred.setHighKeyComparator(predicate.getHighKeyComparator());

    int numBTrees = lsmInitialState.getNumBTrees();
    rangeCursors = new IIndexCursor[numBTrees];
    for (int i = 0; i < numBTrees; i++) {
      IBTreeLeafFrame leafFrame =
          (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
      rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
    }
    setPriorityQueueComparator();

    int cursorIx = 0;
    ListIterator<ILSMComponent> btreesIter = operationalComponents.listIterator();
    if (includeMemComponent) {
      // Open cursor of in-memory BTree at index 0.
      memBTreeAccessor.search(rangeCursors[cursorIx], searchPred);
      // Skip 0 because it is the in-memory BTree.
      ++cursorIx;
      btreesIter.next();
    }

    // Open cursors of on-disk BTrees.
    int numDiskComponents = includeMemComponent ? numBTrees - 1 : numBTrees;
    ITreeIndexAccessor[] diskBTreeAccessors = new ITreeIndexAccessor[numDiskComponents];
    int diskBTreeIx = 0;
    while (btreesIter.hasNext()) {
      BTree diskBTree = (BTree) ((LSMBTreeImmutableComponent) btreesIter.next()).getBTree();
      diskBTreeAccessors[diskBTreeIx] =
          diskBTree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
      diskBTreeAccessors[diskBTreeIx].search(rangeCursors[cursorIx], searchPred);
      cursorIx++;
      diskBTreeIx++;
    }
    initPriorityQueue();
    proceed = true;
  }
  @Override
  public void open() throws HyracksDataException {
    accessor = new FrameTupleAccessor(treeIndexOpHelper.getTaskContext().getFrameSize(), recDesc);

    try {
      treeIndexOpHelper.open();
      btree = (BTree) treeIndexOpHelper.getIndexInstance();
      cursorFrame = btree.getLeafFrameFactory().createFrame();
      setCursor();
      writer.open();

      rangePred = new RangePredicate(null, null, true, true, null, null);
      int lowKeySearchFields = btree.getComparatorFactories().length;
      IBinaryComparator[] lowKeySearchComparators = new IBinaryComparator[lowKeySearchFields];
      for (int i = 0; i < lowKeySearchFields; i++) {
        lowKeySearchComparators[i] = btree.getComparatorFactories()[i].createBinaryComparator();
      }
      lowKeySearchCmp = new MultiComparator(lowKeySearchComparators);

      writeBuffer = treeIndexOpHelper.getTaskContext().allocateFrame();
      tb = new ArrayTupleBuilder(btree.getFieldCount());
      dos = tb.getDataOutput();
      appender = new FrameTupleAppender(treeIndexOpHelper.getTaskContext().getFrameSize());
      appender.reset(writeBuffer, true);

      indexAccessor =
          btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);

      /** set the search cursor */
      rangePred.setLowKey(null, true);
      rangePred.setHighKey(null, true);
      cursor.reset();
      indexAccessor.search(cursor, rangePred);

      /** set up current top tuple */
      if (cursor.hasNext()) {
        cursor.next();
        currentTopTuple = cursor.getTuple();
        match = false;
      }

    } catch (Exception e) {
      treeIndexOpHelper.close();
      throw new HyracksDataException(e);
    }
  }
  @Override
  public void open() throws HyracksDataException {
    /** open the function */
    functionProxy.functionOpen();
    accessor = new FrameTupleAccessor(treeIndexHelper.getTaskContext().getFrameSize(), recDesc);

    try {
      treeIndexHelper.open();
      btree = (BTree) treeIndexHelper.getIndexInstance();
      cursorFrame = btree.getLeafFrameFactory().createFrame();
      setCursor();

      // Construct range predicate.
      lowKeySearchCmp = BTreeUtils.getSearchMultiComparator(btree.getComparatorFactories(), lowKey);
      highKeySearchCmp =
          BTreeUtils.getSearchMultiComparator(btree.getComparatorFactories(), highKey);
      rangePred =
          new RangePredicate(
              null, null, lowKeyInclusive, highKeyInclusive, lowKeySearchCmp, highKeySearchCmp);

      writeBuffer = treeIndexHelper.getTaskContext().allocateFrame();
      tb = new ArrayTupleBuilder(btree.getFieldCount());
      dos = tb.getDataOutput();
      appender = new FrameTupleAppender(treeIndexHelper.getTaskContext().getFrameSize());
      appender.reset(writeBuffer, true);
      indexAccessor =
          btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);

      cloneUpdateTb = new ArrayTupleBuilder(btree.getFieldCount());
      updateBuffer.setFieldCount(btree.getFieldCount());
    } catch (Exception e) {
      treeIndexHelper.close();
      throw new HyracksDataException(e);
    }
  }
コード例 #4
0
 @Override
 public IBinaryComparatorFactory[] getComparatorFactories() {
   BTree btree = (BTree) index;
   return btree.getComparatorFactories();
 }
コード例 #5
0
 @Override
 public int getKeyFieldCount() {
   BTree btree = (BTree) index;
   return btree.getComparatorFactories().length;
 }