Search in sources :

Example 1 with FrameFixedFieldAppender

use of org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender in project asterixdb by apache.

the class InputFrameGenerator method generateDataFrame.

public List<IFrame> generateDataFrame(RecordDescriptor recordDescriptor, List<Object[]> listOfObject) throws HyracksDataException {
    List<IFrame> listFrame = new ArrayList<>();
    VSizeFrame frame = new VSizeFrame(manager);
    FrameFixedFieldAppender appender = new FrameFixedFieldAppender(recordDescriptor.getFieldCount());
    appender.reset(frame, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(manager.getInitialFrameSize());
    DataOutputStream ds = new DataOutputStream(baos);
    for (Object[] objs : listOfObject) {
        for (int i = 0; i < recordDescriptor.getFieldCount(); i++) {
            baos.reset();
            recordDescriptor.getFields()[i].serialize(objs[i], ds);
            if (!appender.appendField(baos.toByteArray(), 0, baos.size())) {
                listFrame.add(frame);
                frame = new VSizeFrame(manager);
                appender.resetWithLeftOverData(frame);
                if (!appender.appendField(baos.toByteArray(), 0, baos.size())) {
                    throw new HyracksDataException("Should never happen!");
                }
            }
        }
    }
    listFrame.add(frame);
    return listFrame;
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) FrameFixedFieldAppender(org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with FrameFixedFieldAppender

use of org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender in project asterixdb by apache.

the class FrameFixedFieldTupleAppenderTest method createAppender.

@Before
public void createAppender() throws HyracksDataException {
    appender = new FrameFixedFieldAppender(fields.length);
    FrameManager manager = new FrameManager(TEST_FRAME_SIZE);
    IFrame frame = new VSizeFrame(manager);
    appender.reset(frame, true);
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) FrameFixedFieldAppender(org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender) FrameManager(org.apache.hyracks.control.nc.resources.memory.FrameManager) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) Before(org.junit.Before)

Aggregations

IFrame (org.apache.hyracks.api.comm.IFrame)2 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)2 FrameFixedFieldAppender (org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldAppender)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 FrameManager (org.apache.hyracks.control.nc.resources.memory.FrameManager)1 Before (org.junit.Before)1