Search in sources :

Example 41 with FrameTupleAppender

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);
    }
}
Also used : FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) UTF8StringSerializerDeserializer(org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer) HashMap(java.util.HashMap) Map(java.util.Map) GroupVSizeFrame(org.apache.hyracks.dataflow.std.sort.util.GroupVSizeFrame) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame)

Example 42 with FrameTupleAppender

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;
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) FixedSizeFrame(org.apache.hyracks.api.comm.FixedSizeFrame) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)42 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)32 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)17 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)14 DataOutput (java.io.DataOutput)10 IFrame (org.apache.hyracks.api.comm.IFrame)8 ByteBuffer (java.nio.ByteBuffer)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 FixedSizeFrame (org.apache.hyracks.api.comm.FixedSizeFrame)6 IFrameTupleAppender (org.apache.hyracks.api.comm.IFrameTupleAppender)6 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)6 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)6 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)5 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)5 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4