Search in sources :

Example 1 with ReferenceEntry

use of org.apache.hyracks.dataflow.std.util.ReferenceEntry in project asterixdb by apache.

the class RunMergingFrameReader method createEntryComparator.

private Comparator<ReferenceEntry> createEntryComparator(final IBinaryComparator[] comparators) {
    return new Comparator<ReferenceEntry>() {

        public int compare(ReferenceEntry tp1, ReferenceEntry tp2) {
            int nmk1 = tp1.getNormalizedKey();
            int nmk2 = tp2.getNormalizedKey();
            if (nmk1 != nmk2) {
                return ((((long) nmk1) & 0xffffffffL) < (((long) nmk2) & 0xffffffffL)) ? -1 : 1;
            }
            IFrameTupleAccessor fta1 = tp1.getAccessor();
            IFrameTupleAccessor fta2 = tp2.getAccessor();
            byte[] b1 = fta1.getBuffer().array();
            byte[] b2 = fta2.getBuffer().array();
            int[] tPointers1 = tp1.getTPointers();
            int[] tPointers2 = tp2.getTPointers();
            for (int f = 0; f < sortFields.length; ++f) {
                int c;
                try {
                    c = comparators[f].compare(b1, tPointers1[2 * f + 1], tPointers1[2 * f + 2], b2, tPointers2[2 * f + 1], tPointers2[2 * f + 2]);
                    if (c != 0) {
                        return c;
                    }
                } catch (HyracksDataException e) {
                    throw new IllegalArgumentException(e);
                }
            }
            int runid1 = tp1.getRunid();
            int runid2 = tp2.getRunid();
            return runid1 < runid2 ? -1 : (runid1 == runid2 ? 0 : 1);
        }
    };
}
Also used : ReferenceEntry(org.apache.hyracks.dataflow.std.util.ReferenceEntry) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Comparator(java.util.Comparator) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator)

Example 2 with ReferenceEntry

use of org.apache.hyracks.dataflow.std.util.ReferenceEntry in project asterixdb by apache.

the class RunMergingFrameReader method nextFrame.

@Override
public boolean nextFrame(IFrame outFrame) throws HyracksDataException {
    outFrameAppender.reset(outFrame, true);
    while (!topTuples.areRunsExhausted() && tupleCount < topK) {
        ReferenceEntry top = topTuples.peek();
        int runIndex = top.getRunid();
        IFrameTupleAccessor fta = top.getAccessor();
        int tupleIndex = top.getTupleIndex();
        if (!outFrameAppender.append(fta, tupleIndex)) {
            return true;
        } else {
            tupleCount++;
        }
        ++tupleIndexes[runIndex];
        setNextTopTuple(runIndex, tupleIndexes, runCursors, inFrames, tupleAccessors, topTuples);
    }
    if (outFrameAppender.getTupleCount() > 0) {
        return true;
    }
    return false;
}
Also used : ReferenceEntry(org.apache.hyracks.dataflow.std.util.ReferenceEntry) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor)

Example 3 with ReferenceEntry

use of org.apache.hyracks.dataflow.std.util.ReferenceEntry in project asterixdb by apache.

the class RunMergingFrameReader method open.

@Override
public void open() throws HyracksDataException {
    tupleCount = 0;
    tupleAccessors = new IFrameTupleAccessor[runCursors.size()];
    outFrameAppender = new FrameTupleAppender();
    Comparator<ReferenceEntry> comparator = createEntryComparator(comparators);
    topTuples = new ReferencedPriorityQueue(runCursors.size(), comparator, sortFields, nmkComputer);
    tupleIndexes = new int[runCursors.size()];
    for (int i = 0; i < runCursors.size(); i++) {
        tupleIndexes[i] = 0;
        int runIndex = topTuples.peek().getRunid();
        runCursors.get(runIndex).open();
        if (runCursors.get(runIndex).nextFrame(inFrames.get(runIndex))) {
            tupleAccessors[runIndex] = new GroupFrameAccessor(ctx.getInitialFrameSize(), recordDesc);
            tupleAccessors[runIndex].reset(inFrames.get(runIndex).getBuffer());
            setNextTopTuple(runIndex, tupleIndexes, runCursors, inFrames, tupleAccessors, topTuples);
        } else {
            closeRun(runIndex, runCursors, tupleAccessors);
            topTuples.pop();
        }
    }
}
Also used : ReferenceEntry(org.apache.hyracks.dataflow.std.util.ReferenceEntry) GroupFrameAccessor(org.apache.hyracks.dataflow.std.sort.util.GroupFrameAccessor) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ReferencedPriorityQueue(org.apache.hyracks.dataflow.std.util.ReferencedPriorityQueue)

Aggregations

ReferenceEntry (org.apache.hyracks.dataflow.std.util.ReferenceEntry)3 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)2 Comparator (java.util.Comparator)1 IBinaryComparator (org.apache.hyracks.api.dataflow.value.IBinaryComparator)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)1 GroupFrameAccessor (org.apache.hyracks.dataflow.std.sort.util.GroupFrameAccessor)1 ReferencedPriorityQueue (org.apache.hyracks.dataflow.std.util.ReferencedPriorityQueue)1