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);
}
};
}
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;
}
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();
}
}
}
Aggregations