Search in sources :

Example 1 with FixedSizeFrameTupleAccessor

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

the class FixedSizeFrameTupleTest method singleFieldTest.

/**
     * This test verifies the correct behavior of the FixedSizeFrameTuple class.
     * Frames containing FixedSizeFrameTuple's require neither tuple slots nor
     * field slots. The tests inserts generated data into a frame until the
     * frame is full, and then verifies the frame's contents.
     *
     */
@Test
public void singleFieldTest() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(FRAME_SIZE);
    ITypeTraits[] fields = new ITypeTraits[1];
    fields[0] = IntegerPointable.TYPE_TRAITS;
    FixedSizeFrameTupleAppender ftapp = new FixedSizeFrameTupleAppender(FRAME_SIZE, fields);
    FixedSizeFrameTupleAccessor ftacc = new FixedSizeFrameTupleAccessor(FRAME_SIZE, fields);
    boolean frameHasSpace = true;
    ArrayList<Integer> check = new ArrayList<Integer>();
    ftapp.reset(buffer, true);
    while (frameHasSpace) {
        int val = rnd.nextInt();
        frameHasSpace = ftapp.append(val);
        if (frameHasSpace) {
            check.add(val);
            ftapp.incrementTupleCount(1);
        }
    }
    ftacc.reset(buffer);
    for (int i = 0; i < ftacc.getTupleCount(); i++) {
        int val = IntegerPointable.getInteger(ftacc.getBuffer().array(), ftacc.getTupleStartOffset(i));
        Assert.assertEquals(check.get(i).intValue(), val);
    }
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ArrayList(java.util.ArrayList) FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) ByteBuffer(java.nio.ByteBuffer) FixedSizeFrameTupleAppender(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAppender) Test(org.junit.Test)

Example 2 with FixedSizeFrameTupleAccessor

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

the class AbstractTOccurrenceSearcher method printNewResults.

public void printNewResults(int maxResultBufIdx, List<ByteBuffer> buffer) {
    StringBuffer strBuffer = new StringBuffer();
    FixedSizeFrameTupleAccessor resultFrameTupleAcc = searchResult.getAccessor();
    for (int i = 0; i <= maxResultBufIdx; i++) {
        ByteBuffer testBuf = buffer.get(i);
        resultFrameTupleAcc.reset(testBuf);
        for (int j = 0; j < resultFrameTupleAcc.getTupleCount(); j++) {
            strBuffer.append(IntegerPointable.getInteger(resultFrameTupleAcc.getBuffer().array(), resultFrameTupleAcc.getFieldStartOffset(j, 0)) + ",");
            strBuffer.append(IntegerPointable.getInteger(resultFrameTupleAcc.getBuffer().array(), resultFrameTupleAcc.getFieldStartOffset(j, 1)) + " ");
        }
    }
    System.out.println(strBuffer.toString());
}
Also used : FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) ByteBuffer(java.nio.ByteBuffer)

Example 3 with FixedSizeFrameTupleAccessor

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor 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 4 with FixedSizeFrameTupleAccessor

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor 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 5 with FixedSizeFrameTupleAccessor

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor 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)5 FixedSizeFrameTupleAccessor (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor)5 FixedSizeTupleReference (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeTupleReference)3 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)2 ArrayList (java.util.ArrayList)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 FixedSizeFrameTupleAppender (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAppender)1 Test (org.junit.Test)1