use of org.apache.hyracks.api.comm.IFrameTupleAccessor in project asterixdb by apache.
the class FieldHashPartitionComputerFamily method createPartitioner.
@Override
public ITuplePartitionComputer createPartitioner(int seed) {
final IBinaryHashFunction[] hashFunctions = new IBinaryHashFunction[hashFunctionGeneratorFactories.length];
for (int i = 0; i < hashFunctionGeneratorFactories.length; ++i) {
hashFunctions[i] = hashFunctionGeneratorFactories[i].createBinaryHashFunction(seed);
}
return new ITuplePartitionComputer() {
@Override
public int partition(IFrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
int h = 0;
int startOffset = accessor.getTupleStartOffset(tIndex);
int slotLength = accessor.getFieldSlotsLength();
for (int j = 0; j < hashFields.length; ++j) {
int fIdx = hashFields[j];
IBinaryHashFunction hashFn = hashFunctions[j];
int fStart = accessor.getFieldStartOffset(tIndex, fIdx);
int fEnd = accessor.getFieldEndOffset(tIndex, fIdx);
int fh = hashFn.hash(accessor.getBuffer().array(), startOffset + slotLength + fStart, fEnd - fStart);
h += fh;
}
if (h < 0) {
h = -(h + 1);
}
return h % nParts;
}
};
}
use of org.apache.hyracks.api.comm.IFrameTupleAccessor in project asterixdb by apache.
the class FrameFixedFieldTupleAppenderTest method testAppendLargeFieldShouldSucceed.
@Test
public void testAppendLargeFieldShouldSucceed() throws HyracksDataException {
IFrameTupleAccessor accessor = prepareData(DATA_TYPE.ONE_FIELD_LONG);
testProcess(accessor);
}
use of org.apache.hyracks.api.comm.IFrameTupleAccessor in project asterixdb by apache.
the class AbstractIntegrationTest method readResults.
protected List<String> readResults(JobSpecification spec, JobId jobId, ResultSetId resultSetId) throws Exception {
int nReaders = 1;
IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor();
IHyracksDataset hyracksDataset = new HyracksDataset(hcc, spec.getFrameSize(), nReaders);
IHyracksDatasetReader reader = hyracksDataset.createReader(jobId, resultSetId);
List<String> resultRecords = new ArrayList<>();
ByteBufferInputStream bbis = new ByteBufferInputStream();
FrameManager resultDisplayFrameMgr = new FrameManager(spec.getFrameSize());
VSizeFrame frame = new VSizeFrame(resultDisplayFrameMgr);
int readSize = reader.read(frame);
while (readSize > 0) {
try {
frameTupleAccessor.reset(frame.getBuffer());
for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
int start = frameTupleAccessor.getTupleStartOffset(tIndex);
int length = frameTupleAccessor.getTupleEndOffset(tIndex) - start;
bbis.setByteBuffer(frame.getBuffer(), start);
byte[] recordBytes = new byte[length];
bbis.read(recordBytes, 0, length);
resultRecords.add(new String(recordBytes, 0, length));
}
} finally {
bbis.close();
}
readSize = reader.read(frame);
}
return resultRecords;
}
use of org.apache.hyracks.api.comm.IFrameTupleAccessor 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.api.comm.IFrameTupleAccessor 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;
}
Aggregations