use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender in project asterixdb by apache.
the class AbstractRunGeneratorTest method prepareData.
static void prepareData(IHyracksTaskContext ctx, List<IFrame> frameList, int minDataSize, int minRecordSize, int maxRecordSize, Map<Integer, String> specialData, Map<Integer, String> keyValuePair) throws HyracksDataException {
ArrayTupleBuilder tb = new ArrayTupleBuilder(RecordDesc.getFieldCount());
FrameTupleAppender appender = new FrameTupleAppender();
int datasize = 0;
if (specialData != null) {
for (Map.Entry<Integer, String> entry : specialData.entrySet()) {
tb.reset();
tb.addField(IntegerSerializerDeserializer.INSTANCE, entry.getKey());
tb.addField(new UTF8StringSerializerDeserializer(), entry.getValue());
VSizeFrame frame = new VSizeFrame(ctx, FrameHelper.calcAlignedFrameSizeToStore(tb.getFieldEndOffsets().length, tb.getSize(), ctx.getInitialFrameSize()));
appender.reset(frame, true);
assertTrue(appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize()));
frameList.add(frame);
datasize += frame.getFrameSize();
}
keyValuePair.putAll(specialData);
}
VSizeFrame frame = new VSizeFrame(ctx, ctx.getInitialFrameSize());
appender.reset(frame, true);
while (datasize < minDataSize) {
tb.reset();
int key = GRandom.nextInt(minDataSize + 1);
if (!keyValuePair.containsKey(key)) {
String value = generateRandomRecord(minRecordSize, maxRecordSize);
tb.addField(IntegerSerializerDeserializer.INSTANCE, key);
tb.addField(new UTF8StringSerializerDeserializer(), value);
if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
frameList.add(frame);
datasize += frame.getFrameSize();
frame = new VSizeFrame(ctx, FrameHelper.calcAlignedFrameSizeToStore(tb.getFieldEndOffsets().length, tb.getSize(), ctx.getInitialFrameSize()));
appender.reset(frame, true);
assertTrue(appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize()));
}
keyValuePair.put(key, value);
}
}
if (appender.getTupleCount() > 0) {
frameList.add(frame);
}
}
use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender in project asterixdb by apache.
the class TopKRunGeneratorTest method prepareSortedData.
private ByteBuffer prepareSortedData(Map<Integer, String> keyValuePair) throws HyracksDataException {
ByteBuffer buffer = ByteBuffer.allocate(PAGE_SIZE * NUM_PAGES);
IFrame inputFrame = new FixedSizeFrame(buffer);
FrameTupleAppender appender = new FrameTupleAppender();
appender.reset(inputFrame, true);
ArrayTupleBuilder builder = new ArrayTupleBuilder(RecordDesc.getFieldCount());
for (Map.Entry<Integer, String> entry : keyValuePair.entrySet()) {
builder.reset();
builder.addField(SerDers[0], entry.getKey());
builder.addField(SerDers[1], entry.getValue());
appender.append(builder.getFieldEndOffsets(), builder.getByteArray(), 0, builder.getSize());
}
return buffer;
}
Aggregations