Search in sources :

Example 1 with FixedSizeTupleReference

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference in project asterixdb by apache.

the class InvertedListMerger method mergeSuffixListProbe.

protected void mergeSuffixListProbe(IInvertedListCursor invListCursor, SearchResult prevSearchResult, SearchResult newSearchResult, int invListIx, int numInvLists, int occurrenceThreshold) throws HyracksDataException {
    int prevBufIdx = 0;
    int maxPrevBufIdx = prevSearchResult.getCurrentBufferIndex();
    ByteBuffer prevCurrentBuffer = prevSearchResult.getBuffers().get(0);
    FixedSizeFrameTupleAccessor resultFrameTupleAcc = prevSearchResult.getAccessor();
    FixedSizeTupleReference resultTuple = prevSearchResult.getTuple();
    int resultTidx = 0;
    resultFrameTupleAcc.reset(prevCurrentBuffer);
    while (resultTidx < resultFrameTupleAcc.getTupleCount()) {
        resultTuple.reset(prevCurrentBuffer.array(), resultFrameTupleAcc.getTupleStartOffset(resultTidx));
        int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1));
        if (invListCursor.containsKey(resultTuple, invListCmp)) {
            count++;
            newSearchResult.append(resultTuple, count);
        } else {
            if (count + numInvLists - invListIx > occurrenceThreshold) {
                newSearchResult.append(resultTuple, count);
            }
        }
        resultTidx++;
        if (resultTidx >= resultFrameTupleAcc.getTupleCount()) {
            prevBufIdx++;
            if (prevBufIdx <= maxPrevBufIdx) {
                prevCurrentBuffer = prevSearchResult.getBuffers().get(prevBufIdx);
                resultFrameTupleAcc.reset(prevCurrentBuffer);
                resultTidx = 0;
            }
        }
    }
}
Also used : FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) FixedSizeTupleReference(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference) ByteBuffer(java.nio.ByteBuffer)

Example 2 with FixedSizeTupleReference

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference in project asterixdb by apache.

the class InvertedListMerger method mergeSuffixListScan.

protected void mergeSuffixListScan(IInvertedListCursor invListCursor, SearchResult prevSearchResult, SearchResult newSearchResult, int invListIx, int numInvLists, int occurrenceThreshold) throws HyracksDataException {
    int prevBufIdx = 0;
    int maxPrevBufIdx = prevSearchResult.getCurrentBufferIndex();
    ByteBuffer prevCurrentBuffer = prevSearchResult.getBuffers().get(0);
    FixedSizeFrameTupleAccessor resultFrameTupleAcc = prevSearchResult.getAccessor();
    FixedSizeTupleReference resultTuple = prevSearchResult.getTuple();
    boolean advanceCursor = true;
    boolean advancePrevResult = false;
    int resultTidx = 0;
    resultFrameTupleAcc.reset(prevCurrentBuffer);
    int invListTidx = 0;
    int invListNumTuples = invListCursor.size();
    if (invListCursor.hasNext()) {
        invListCursor.next();
    }
    while (invListTidx < invListNumTuples && resultTidx < resultFrameTupleAcc.getTupleCount()) {
        ITupleReference invListTuple = invListCursor.getTuple();
        resultTuple.reset(prevCurrentBuffer.array(), resultFrameTupleAcc.getTupleStartOffset(resultTidx));
        int cmp = invListCmp.compare(invListTuple, resultTuple);
        if (cmp == 0) {
            int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1)) + 1;
            newSearchResult.append(resultTuple, count);
            advanceCursor = true;
            advancePrevResult = true;
        } else {
            if (cmp < 0) {
                advanceCursor = true;
                advancePrevResult = false;
            } else {
                int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1));
                if (count + numInvLists - invListIx > occurrenceThreshold) {
                    newSearchResult.append(resultTuple, count);
                }
                advanceCursor = false;
                advancePrevResult = true;
            }
        }
        if (advancePrevResult) {
            resultTidx++;
            if (resultTidx >= resultFrameTupleAcc.getTupleCount()) {
                prevBufIdx++;
                if (prevBufIdx <= maxPrevBufIdx) {
                    prevCurrentBuffer = prevSearchResult.getBuffers().get(prevBufIdx);
                    resultFrameTupleAcc.reset(prevCurrentBuffer);
                    resultTidx = 0;
                }
            }
        }
        if (advanceCursor) {
            invListTidx++;
            if (invListCursor.hasNext()) {
                invListCursor.next();
            }
        }
    }
    // append remaining elements from previous result set
    while (resultTidx < resultFrameTupleAcc.getTupleCount()) {
        resultTuple.reset(prevCurrentBuffer.array(), resultFrameTupleAcc.getTupleStartOffset(resultTidx));
        int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1));
        if (count + numInvLists - invListIx > occurrenceThreshold) {
            newSearchResult.append(resultTuple, count);
        }
        resultTidx++;
        if (resultTidx >= resultFrameTupleAcc.getTupleCount()) {
            prevBufIdx++;
            if (prevBufIdx <= maxPrevBufIdx) {
                prevCurrentBuffer = prevSearchResult.getBuffers().get(prevBufIdx);
                resultFrameTupleAcc.reset(prevCurrentBuffer);
                resultTidx = 0;
            }
        }
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) FixedSizeTupleReference(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference) ByteBuffer(java.nio.ByteBuffer)

Example 3 with FixedSizeTupleReference

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference in project asterixdb by apache.

the class InvertedListMerger method mergePrefixList.

protected void mergePrefixList(IInvertedListCursor invListCursor, SearchResult prevSearchResult, SearchResult newSearchResult) throws HyracksDataException {
    int prevBufIdx = 0;
    int maxPrevBufIdx = prevSearchResult.getCurrentBufferIndex();
    ByteBuffer prevCurrentBuffer = prevSearchResult.getBuffers().get(0);
    FixedSizeFrameTupleAccessor resultFrameTupleAcc = prevSearchResult.getAccessor();
    FixedSizeTupleReference resultTuple = prevSearchResult.getTuple();
    boolean advanceCursor = true;
    boolean advancePrevResult = false;
    int resultTidx = 0;
    resultFrameTupleAcc.reset(prevCurrentBuffer);
    int invListTidx = 0;
    int invListNumTuples = invListCursor.size();
    if (invListCursor.hasNext()) {
        invListCursor.next();
    }
    while (invListTidx < invListNumTuples && resultTidx < resultFrameTupleAcc.getTupleCount()) {
        ITupleReference invListTuple = invListCursor.getTuple();
        resultTuple.reset(prevCurrentBuffer.array(), resultFrameTupleAcc.getTupleStartOffset(resultTidx));
        int cmp = invListCmp.compare(invListTuple, resultTuple);
        if (cmp == 0) {
            int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1)) + 1;
            newSearchResult.append(resultTuple, count);
            advanceCursor = true;
            advancePrevResult = true;
        } else {
            if (cmp < 0) {
                int count = 1;
                newSearchResult.append(invListTuple, count);
                advanceCursor = true;
                advancePrevResult = false;
            } else {
                int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1));
                newSearchResult.append(resultTuple, count);
                advanceCursor = false;
                advancePrevResult = true;
            }
        }
        if (advancePrevResult) {
            resultTidx++;
            if (resultTidx >= resultFrameTupleAcc.getTupleCount()) {
                prevBufIdx++;
                if (prevBufIdx <= maxPrevBufIdx) {
                    prevCurrentBuffer = prevSearchResult.getBuffers().get(prevBufIdx);
                    resultFrameTupleAcc.reset(prevCurrentBuffer);
                    resultTidx = 0;
                }
            }
        }
        if (advanceCursor) {
            invListTidx++;
            if (invListCursor.hasNext()) {
                invListCursor.next();
            }
        }
    }
    // append remaining new elements from inverted list
    while (invListTidx < invListNumTuples) {
        ITupleReference invListTuple = invListCursor.getTuple();
        newSearchResult.append(invListTuple, 1);
        invListTidx++;
        if (invListCursor.hasNext()) {
            invListCursor.next();
        }
    }
    // append remaining elements from previous result set
    while (resultTidx < resultFrameTupleAcc.getTupleCount()) {
        resultTuple.reset(prevCurrentBuffer.array(), resultFrameTupleAcc.getTupleStartOffset(resultTidx));
        int count = IntegerPointable.getInteger(resultTuple.getFieldData(0), resultTuple.getFieldStart(resultTuple.getFieldCount() - 1));
        newSearchResult.append(resultTuple, count);
        resultTidx++;
        if (resultTidx >= resultFrameTupleAcc.getTupleCount()) {
            prevBufIdx++;
            if (prevBufIdx <= maxPrevBufIdx) {
                prevCurrentBuffer = prevSearchResult.getBuffers().get(prevBufIdx);
                resultFrameTupleAcc.reset(prevCurrentBuffer);
                resultTidx = 0;
            }
        }
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) FixedSizeTupleReference(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 FixedSizeFrameTupleAccessor (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor)3 FixedSizeTupleReference (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference)3 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)2